I need to search through the whole workbook and find the matching results. The results (It could be hundreds of record) will then be displayed in a new worksheet called "Result".
Following is what I've done so far, if anyone can help me solving the problem, I'll be appreciated. Thanks
***********************************************************
Private Sub CommandButton1_Click()
Dim counter As Integer
Dim sheetCount As Integer
Dim searchCriteria As Variant
Dim findResult As String
Dim reportRow As Integer
Application.Worksheets("Result").Columns("A:Z").Clear
searchCriteria = TextBox1.Text
reportRow = 2
Application.Worksheets("Result").Range("A1:Z1").Font.FontStyle = "Bold Italic"
Application.Worksheets("Result").Cells(1, 1).Value = "Unique Number"
Application.Worksheets("Result").Cells(1, 2).Value = "Capturers Name"
Application.Worksheets("Result").Cells(1, 3).Value = "Time of Capture"
Application.Worksheets("Result").Cells(1, 4).Value = "Bin No."
Application.Worksheets("Result").Columns("A:Z").AutoFit
Dim startSheet, startCell
Application.ScreenUpdating = False
On Error Resume Next
startCell = ActiveCell.Address
startSheet = ActiveSheet.Name
If searchCriteria = "" Then Exit Sub
If IsError(CDbl(searchCriteria)) = False Then searchCriteria = CDbl(searchCriteria)
sheetCount = ActiveWorkbook.Sheets.Count
counter = 1
Do Until counter > sheetCount
Sheets(counter).Activate
Cells.Find(What:=searchCriteria, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False) _
.Activate
Application.Worksheets("Result").Cells(reportRow, 1).Value = ActiveCell.Offset(0, 0).Value
Application.Worksheets("Result").Cells(reportRow, 2).Value = ActiveCell.Offset(0, 1).Value
Application.Worksheets("Result").Cells(reportRow, 3).Value = ActiveCell.Offset(0, 2).Text
Application.Worksheets("Result").Cells(reportRow, 4).Value = ActiveCell.Offset(0, 3).Value
reportRow = reportRow + 1
counter = counter + 1
Loop
End Sub
Bookmarks