Hi!!! could anyone please help me about querying in excel..
heres the scenario..
i have 2 sheets(sheet1,sheet2)
sheet1 = contain the correct answer
ex. col1 -- 3333 | col2 -- jose reyes
sheet 2 = contains only tha code... ex. col1 -- 3333 (shuffled)
(note.... record count is more than 5000)
now using the sheet1 as basis i need to know the corresponding NAME of the code in sheet 2...
actually i have a code... its working fine.. but i always run out of memory... pls help... its making me nuts...
heres the code::::
form___________
Private Sub CommandButton1_Click()
Dim st As String
Dim cnt As Long
cnt = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\NAME.xls;" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"";"
Do
st = SearchNAMElink(ActiveSheet.Cells(cnt, 2).Value)
ActiveSheet.Cells(cnt, 4).Value = st
If ActiveSheet.Cells(cnt, 2).Value = "" And ActiveSheet.Cells(cnt + 1, 2).Value = "" Then
Exit Do
End If
Label1.Caption = "RECORDS :" & cnt - 1
cnt = cnt + 1
DoEvents
Loop While True
Set objConnection = Nothing
Unload Me
End Sub
inA MODULE___________
Public Function SearchNAMElink (stcode As String) As String
If stcode = "" Then Exit Function
objRecordset.Open "Select link FROM [NAMElinks$] where CODE = '" & stcode & "'", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText
If Not objRecordset.EOF Then
SearchOthlink = Format(objRecordset!link, "00000")
End If
DoEvents
objRecordset.Close
End Function
:pretty: