Hi
I should start by explaining that I am new to VBA setting up Macro's on Excel.
I reviewed your Fast Search Entire Excel Workbook & Return All Results into a Dashboard (https://www.youtube.com/watch?v=DOW3SjBjg6I) video and found it be very helpful and allowed me to set up the Macro. However, I need to search over 3 columns (noting to complicated just a single word in each). I have tried playing with it but I cannot get it to work. Can you advise how I can set this up, if it is possible?
I have pasted the code that i am using in a test set up. The columns that would need to be searched are animal (3 and 4). I have attached the workbook but it just basic so I could play with the code.
Kind regards
Ben
Sub Data_search()
Dim ws As Worksheet
Dim Main As Worksheet
Dim dataArray As Variant
Dim DatatoShowArray As Variant
Set Main = Sheets("Main")
dataColumnStart = 1
dataColumnEnd = 5
dataColumnWidth = dataColumnEnd - dataColumnStart
DataRowStart = 2
MainDataColumnStart = 2
searchValue = Main.Range("C4").Value
fieldValue = Main.Range("E4").Value
Call Clear_Data
If (fieldValue = "Number") Then
SearchField = 1
ElseIf (fieldValue = "Person") Then
SearchField = 2
ElseIf (fieldValue = "Animal") Then
SearchField = 3
End If
'Loop information and transfer data
For Each ws In Worksheets
If (ws.Name <> "Main") Then
dataArray = ws.Range(ws.Cells(DataRowStart, dataColumnStart), ws.Cells(ws.Cells(Rows.Count, dataColumnStart).End(xlUp).Row, dataColumnEnd)).Value
ReDim DatatoShowArray(1 To UBound(dataArray, 1), 1 To UBound(dataArray, 2))
j = 1
For i = 1 To UBound(dataArray, 1)
If (dataArray(i, SearchField) = searchValue) Then
For k = 1 To UBound(dataArray, 2)
DatatoShowArray(j, k) = dataArray(i, k)
Next k
j = j + 1
End If
Next i
nextRow = Main.Cells(Rows.Count, MainDataColumnStart).End(xlUp).Row + 1
Main.Range(Cells(nextRow, MainDataColumnStart), Cells(nextRow + UBound(DatatoShowArray, 1) - 1, MainDataColumnStart + dataColumnWidth)).Value = DatatoShowArray
End If
Next ws
End Sub