Finding String in Excel Using VB6 ADO, Return Column & Row Problems

Qpido

New Member
Joined
Oct 9, 2007
Messages
30
Dear helpful forum members,

I am trying to use ADO via VB6 to find a specific input in row A of my excel sheet.

I then want it to return the Column and Row to me separately.

I'm having a huge problem finding any precise information on how to do this.

I have a code I already use for returning specific values from cells:
Code:
Function Look(ClosedWorkbookFullName As String, _
    SheetName As String, RangeAddress As String) As Variant
    
    Dim conn As Object, rs As Object, SQL As String
    Set conn = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")
    
    conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & ClosedWorkbookFullName & _
    ";Extended Properties=""Excel 8.0;HDR=NO;"""
	
    SQL = "Select * From [" & SheetName & "$" & RangeAddress & ":" & RangeAddress & "]"
    rs.Open SQL, conn, 1, 3
    Look = rs.Fields(0).Value
    rs.Close: conn.Close
    
    If IsNull(Look) Then Look = ""

End Function

Now I want something like this I can use as a function, but it obviously needs tweaks.

Could anyone assist me in this matter?

As always, thank you very much.

Jerome
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Still need a solution to this, if anyone could help that would be great.

I have managed to upgrade it to something like this to reflect what I'm trying to do exactly, I am trying to get the column of the field where my search string is located.
Code:
Function HorizontalFind(StrFind As String, ClosedWorkbookFullName As String, _
    SheetName As String, iStart As Integer) As Variant
    
    Dim conn As Object, rs As Object, SQL As String
    Dim i As Integer
    Set conn = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")
    
    conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & ClosedWorkbookFullName & _
    ";Extended Properties=""Excel 8.0;HDR=NO;"""
    
    SQL = "Select * From [" & SheetName & "$]"
    rs.Open SQL, conn, 1, 1
    
    i = 4
    
        Do While Not rs.EOF
            If StrFind = rs.Fields(i).Value Then
                HorizontalFind = rs.Fields(i).Name
                MsgBox HorizontalFind, vbOKOnly
                'HorizontalFind = rs.AbsolutePosition
                rs.Close: conn.Close
                Exit Function
            Else
                HorizontalFind = "Not Found"
                rs.MoveNext
            End If
            rs.movefirst
            i = i + 1
        Loop
    
    
    If IsNull(HorizontalFind) Then HorizontalFind = ""
End Function

I would call it with something like this:
Code:
sLine = modFunc.HorizontalFind("DE01", sFile, sSheet, 5)

Thanks
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,787
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top