Hello all,
So I'm working with a big worksheet containing delays, these delays are all assigned a code based off of the reason for delay. I'm trying to add a search feature that searches my initial sheet "Raw Data" for all entries of the ata code and than displays them on a new sheet "Output". Below is the code I found and modified to meet my specific needs, but I can't seem to make it keep searching for all entries as opposed to just the initial entry when the code appears. All help is greatly apperciated!
Sub SearchForNumber()
Dim Search As Variant
Dim msg As String, msg1 As String
Dim r As Long
Dim c As Range, Rng As Range
Dim wsOutPut As Worksheet, sh As Worksheet
Set wsOutPut = Worksheets("Output")
'Open inputbox
Top:
msg = ""
Do
Search = InputBox("Enter Search Number Value:", "Search")
If StrPtr(Search) = 0 Then Exit Sub
Loop Until IsNumeric(Search)
Application.ScreenUpdating = False
r = wsOutPut.Cells(wsOutPut.Rows.Count, "A").End(xlUp).Row + 1
For Each sh In Worksheets(Array("Raw Data"))
With sh
.Activate
Set c = .Columns(5).Find(What:=CLng(Search), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not c Is Nothing Then
Set Rng = .Rows(c.Row)
wsOutPut.Rows(r).Value = Rng.Value
r = r + 1
msg = msg & "Sheet: " & sh.Name & " - Record for " & Search & " found." & Chr(10) & Chr(10)
Else
msg = msg & "Sheet: " & sh.Name & " - Record not found!" & Chr(10) & Chr(10)
End If
End With
Next sh
Application.ScreenUpdating = True
msg = MsgBox(msg & Chr(10) & "Do you want to make another search?", 36, "Results")
If msg = 6 Then GoTo Top
End Sub
So I'm working with a big worksheet containing delays, these delays are all assigned a code based off of the reason for delay. I'm trying to add a search feature that searches my initial sheet "Raw Data" for all entries of the ata code and than displays them on a new sheet "Output". Below is the code I found and modified to meet my specific needs, but I can't seem to make it keep searching for all entries as opposed to just the initial entry when the code appears. All help is greatly apperciated!
Sub SearchForNumber()
Dim Search As Variant
Dim msg As String, msg1 As String
Dim r As Long
Dim c As Range, Rng As Range
Dim wsOutPut As Worksheet, sh As Worksheet
Set wsOutPut = Worksheets("Output")
'Open inputbox
Top:
msg = ""
Do
Search = InputBox("Enter Search Number Value:", "Search")
If StrPtr(Search) = 0 Then Exit Sub
Loop Until IsNumeric(Search)
Application.ScreenUpdating = False
r = wsOutPut.Cells(wsOutPut.Rows.Count, "A").End(xlUp).Row + 1
For Each sh In Worksheets(Array("Raw Data"))
With sh
.Activate
Set c = .Columns(5).Find(What:=CLng(Search), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not c Is Nothing Then
Set Rng = .Rows(c.Row)
wsOutPut.Rows(r).Value = Rng.Value
r = r + 1
msg = msg & "Sheet: " & sh.Name & " - Record for " & Search & " found." & Chr(10) & Chr(10)
Else
msg = msg & "Sheet: " & sh.Name & " - Record not found!" & Chr(10) & Chr(10)
End If
End With
Next sh
Application.ScreenUpdating = True
msg = MsgBox(msg & Chr(10) & "Do you want to make another search?", 36, "Results")
If msg = 6 Then GoTo Top
End Sub