belinea2008
Technical User
Hi guys,
I have a workbook that I use as a database and different spreadsheets within the workbook contain different data.
I wish to use one sheet as a search form and use code or a macro to search either specific sheets or/and all sheets depending on the user requirements. So for the purpose of this question lets assume the search sheet is called 'frmSearch' and the sheet cotaining the data is called 'shtData' and these are contained in a workbook called 'myData'
I have found some code on a different forum that will perform the search I need BUT it has to be run from within the sheet containing the data.
How do I refer to the cells on the sheet called 'shtData' using code from my search sheet 'frmSearch' and tell the code to display any data or records found back on my search sheet 'shtData'?
I'm afraid I am rather new to VBA so please be gentle with me
The code I have found follows below.
Thank you for your help in advance
Code start:
Sub Search()
Range("E11").CurrentRegion.ClearContents: Range("E11") = "Results"
FindWhat = Range("E5")
For Each Cell In Range("B2", Range("B" & Rows.Count).End(xlUp))
If InStr(Cell, FindWhat) <> 0 Then
Range("E" & Rows.Count).End(xlUp).Offset(1, 0) = Cell.Offset(, -1)
Range("E" & Rows.Count).End(xlUp).Offset(0, 1) = Cell
Range("E" & Rows.Count).End(xlUp).Offset(0, 2) = Cell.Offset(, 1)
Range("E" & Rows.Count).End(xlUp).Offset(0, 3) = Cell.Offset(, 2)
End If
Next Cell
End Sub
Code End:
I have a workbook that I use as a database and different spreadsheets within the workbook contain different data.
I wish to use one sheet as a search form and use code or a macro to search either specific sheets or/and all sheets depending on the user requirements. So for the purpose of this question lets assume the search sheet is called 'frmSearch' and the sheet cotaining the data is called 'shtData' and these are contained in a workbook called 'myData'
I have found some code on a different forum that will perform the search I need BUT it has to be run from within the sheet containing the data.
How do I refer to the cells on the sheet called 'shtData' using code from my search sheet 'frmSearch' and tell the code to display any data or records found back on my search sheet 'shtData'?
I'm afraid I am rather new to VBA so please be gentle with me
Thank you for your help in advance
Code start:
Sub Search()
Range("E11").CurrentRegion.ClearContents: Range("E11") = "Results"
FindWhat = Range("E5")
For Each Cell In Range("B2", Range("B" & Rows.Count).End(xlUp))
If InStr(Cell, FindWhat) <> 0 Then
Range("E" & Rows.Count).End(xlUp).Offset(1, 0) = Cell.Offset(, -1)
Range("E" & Rows.Count).End(xlUp).Offset(0, 1) = Cell
Range("E" & Rows.Count).End(xlUp).Offset(0, 2) = Cell.Offset(, 1)
Range("E" & Rows.Count).End(xlUp).Offset(0, 3) = Cell.Offset(, 2)
End If
Next Cell
End Sub
Code End: