Good morning, I have a little issue with the below code I am trying to figure out.
The function works correctly it opens a search window it finds the desired value on sheet2 but only returns 1 result regardless of how many instances of that number appear on sheet2. I would like it to show the multiple rows on the message box. currently it shows just the first instance. Included is the code used for the search and also a screen shot showing the value in multiple rows.
Thank you
The function works correctly it opens a search window it finds the desired value on sheet2 but only returns 1 result regardless of how many instances of that number appear on sheet2. I would like it to show the multiple rows on the message box. currently it shows just the first instance. Included is the code used for the search and also a screen shot showing the value in multiple rows.
VBA Code:
Private Sub CommandButton2_Click()
Dim Search As Variant
Dim msg As String
Dim c As Range, Rng As Range
Dim wsOutPut As Worksheet, sh As Worksheet
Set wsOutPut = Worksheets("Sheet2")
'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
For Each sh In Worksheets(Array("Sheet2"))
With sh
.Activate
Set c = .Columns(6).Find(What:=CLng(Search), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=True, _
SearchFormat:=False)
If Not c Is Nothing Then
Set Rng = .Rows(c.Row)
msg = msg & "Serial number found on row " & c.Row & Chr(10) & Chr(10)
Else
msg = msg & "Serial number 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
Thank you