Hi,
I recently started using macro's to make my database searching job easier. This morning i stumbled upon a piece of 'search engine' code that can be used in excel, which works great.
Except, i have a database with columns from A to U, and the code i used from this forum only copies one column to the search page.
I think it is this piece of the code which needs to be modified:
arrTool(2, UBound(arrTool, 2)) = FoundCell.Offset(0, 1)
arrTool(1, UBound(arrTool, 2)) = FoundCell.Value
The FoundCell.Offset(0,1) only takes the value with offset (0,1), while i need the whole row.
How can i modify this?
Thanks in advance!
This is the code:
Sub SearchDM()
Dim arrDM() As Variant
Range("A7", "U" & Cells(Rows.CountLarge, "U").End(xlDown).Row).Clear
arrTool = FindDM(CStr(Trim(Cells(2, 2))))
Range("I7").Resize(UBound(arrTool, 2), UBound(arrTool)) = _
WorksheetFunction.Transpose(arrTool)
End Sub
Private Function FindDM(PartNumber As String) As Variant
Dim ws As Worksheet
Dim FoundCell As Range
Dim LastCell As Range
Dim rngDM As Range
Dim FirstAddr As String
Dim arrTool() As Variant
Set ws = Worksheets("All")
Set rngDM = ws.Range("I2:I" & ws.Cells(Rows.CountLarge, "I").End(xlUp).Row)
With rngDM
Set LastCell = .Cells(.Cells.Count)
End With
Set FoundCell = rngDM.Find(What:=PartNumber, After:=LastCell, LookAt:=xlPart)
If Not FoundCell Is Nothing Then
FirstAddr = FoundCell.Address
End If
ReDim arrTool(1 To 2, 1 To 1)
Do Until FoundCell Is Nothing
arrTool(2, UBound(arrTool, 2)) = FoundCell.Offset(0, 1)
arrTool(1, UBound(arrTool, 2)) = FoundCell.Value
ReDim Preserve arrTool(1 To 2, 1 To UBound(arrTool, 2) + 1)
Set FoundCell = rngDM.FindNext(After:=FoundCell)
If FoundCell.Address = FirstAddr Then
Exit Do
End If
Loop
FindDM = arrTool
End Function
Bookmarks