Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find a string with a Row only work to column Z 1

Status
Not open for further replies.

davedave24

Programmer
Aug 26, 2010
113
GB
I'm attempting to search Row 1 of a sheet for a string in a combobox.

This works fine with my code for searching down a column for a string, but searching the row it only works up to Row Z. From Cols AA-AZ it loads column A, and BA-BZ it loads column B.

Once it has found the name, move down 2 cells, and load that column into an array (which I'm putting in a listbox for this example only).

Code:
    Dim rngFind As Range
    With Sheets("ProductList").Range("1:1")
        Set rngFind = .Find(comboCustomer, , xlValues, MatchCase:=False)
    End With
    
    If Not rngFind Is Nothing Then          'found customer name        
        Application.Goto rngFind, True
        ActiveCell.Offset(2, 0).Select      'move down to first data
        
        'start cell
        Dim rngA As String
        rngA = ActiveCell.Address(False, False)
        
        'startcell column letter
        Dim rngB As String
        rngB = Mid(rngA, 1, 1)
        
        'load the customers into an array
        Dim rngP As Range
        With Sheets("ProductList")
            Set rngP = .Range(.Range(rngA), .Cells(Rows.Count, rngB).End(xlUp))
        End With
        
        'add the customer array to the combobox
        ListBox1.RowSource = rngP.Address(External:=True)
    End If
 
Code:
Dim rngFind As Range[b]
    Dim rA as range[/b]
    With Sheets("ProductList").Range("1:1")
        Set rngFind = .Find(comboCustomer, , xlValues, MatchCase:=False)
    End With
    
    If Not rngFind Is Nothing Then          'found customer name     [b] 
        Set rA = rngFind.offset(2)[/b]

        'load the customers into an array
        Dim rngP As Range
        With Sheets("ProductList")[b]
            Set rngP = .Range(rA, .Cells(Rows.Count, rA.column).End(xlUp))[/b]
        End With
        
        'add the customer array to the combobox
        ListBox1.RowSource = rngP.Address(External:=True)
    End If

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top