Sub FindAndCopyRowsAllSheets()
Dim ws As Worksheet, wsRng As Range, sstr As String, txt As String
Dim foundRng As Range, tempRng As Range, caseSense As Boolean
CountCopyToRow = 2
caseMsg = MsgBox("Make this search CASE-sensitive?", _
vbYesNoCancel)
If caseMsg = vbYes Then
caseSense = True
Else
If caseMsg = vbNo Then
caseSense = False
Else
Exit Sub
End If
End If
If caseSense = True Then
txt = "Enter the value to search" & vbCrLf & vbCrLf & _
"Search is CASE-Sensitve"
Else
txt = "Enter the value to search" & vbCrLf & vbCrLf & _
"Search is NOT case-sensitve"
End If
sstr = InputBox(txt, "Search Value")
If sstr = "" Then Exit Sub
'If you want to search all the sheets for sstr _
loop through all the sheets like below. _
Or you can remove this loop and _
set ws = the sheet to be searched in
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Sheet2" Then
Set wsRng = ws.Range(ws.Range("A1"), _
ws.Range("A1").SpecialCells(xlLastCell))
Set tempRng = ws.Cells(wsRng.Rows.Count, wsRng.Columns.Count)
For Each Row In wsRng.Rows
If foundRng Is Nothing Then
Set tempRng = wsRng.Find(What:=sstr, After:=tempRng, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:= _
caseSense, SearchFormat:=False)
If Not tempRng Is Nothing Then
Set foundRng = tempRng.EntireRow
Else
Exit For
End If
Else
Set tempRng = wsRng.Find(What:=sstr, After:=tempRng, _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:= _
caseSense, SearchFormat:=False)
If Not Intersect(foundRng, tempRng) Is Nothing Then Exit For
Set foundRng = Union(foundRng, tempRng.EntireRow)
End If
Sheets("Sheet2").Rows(CountCopyToRow).Value = _
tempRng.EntireRow.Value
CountCopyToRow = CountCopyToRow + 1
Next Row
End If
Set tempRng = Nothing
Set foundRng = Nothing
Next ws
End Sub