I'm reading from an excel XLS worksheet with no header rows. Some cells in the column have a list of numbers like 12345,12346,12347,12348. Other cells only have one number 12345.
The "LIKE" operator finds the number when there is multiple numbers in a cell, but doesn't find the cells where only one number exists.
SQL = "SELECT * FROM [2010 VIP$] WHERE F9 LIKE '%" & sDealer & "%'"
I tried changing my connection string from: "Data Source=" & dS & ";Extended Properties=""Excel 8.0;HDR=No"""
To (adding IMEX for mixed data types): "Data Source=" & dS & ";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"""
But I get an unknown error when IMEX is added. It's my understanding you can't use the F1, F2, F3 field names without HDR=No.
I tried using the first connection string but changed my SQL to: SQL = "SELECT * FROM [2010 VIP$] WHERE F9 LIKE '%" & sDealer & "%' OR F9='" & sDealer & "'"
But it still doesn't find the cells with only one number.
WHAT GIVES.
Any help would be greatly appreciated.
EDIT: Thanks for the helpful feedback guys, I ended up just using a slower method but it works and still checks 1200 rows in like 2 seconds:
Dim cN As New ADODB.Connection
Dim rS As New ADODB.Recordset
Dim SQL As String
Dim dDealer As Double
Dim WS As Worksheet
Dim sDealer As String, sAmount As String
Dim bFound As Boolean
Set WS = ActiveSheet
cN.Provider = "Microsoft.Jet.OLEDB.4.0"
cN.Open "Data Source=" & MostRecentPath & ";" & _
"Extended Properties=""Excel 8.0;IMEX=1"""
For dDealer = 2 To WS.Range("a60000").End(xlUp).Row
sAmount = WS.Range("c" & dDealer).Value
If Len(sAmount) > 0 Then GoTo skipOne
sDealer = Trim(WS.Range("i" & dDealer).Value)
If Len(sDealer) <> 5 Then GoTo skipOne
If IsNumeric(sDealer) = False Then GoTo skipOne
SQL = "SELECT * FROM [2010 VIP$]"
rS.Open SQL, cN, adOpenStatic, adLockOptimistic
bFound = False
Do While rS.EOF = False
If InStr(1, rS.Fields(8).Value, sDealer) > 0 Then
bFound = True
Exit Do
End If
rS.MoveNext
Loop
rS.Close
If bFound = True Then WS.Range("l" & dDealer).Value = "VIP"
DoEvents
skipOne:
Next dDealer
cN.Close