Public Sub BlankCellsContainingString()
Dim RgToSearch As Range
Dim CharToFind As String
Dim rg As Range
Set RgToSearch = ActiveSheet.Range("A:A")
CharToFind = ">"
Set rg = FindAll(CharToFind, RgToSearch, xlValues, xlPart)
If Not rg Is Nothing Then
rg.ClearContents
End If
End Sub
Sub CopyCellsContainingString()
Dim RgToSearch As Range
Dim CharToFind As String
Dim RgDestination As Range
Dim rg As Range
Set RgToSearch = ActiveSheet.Range("A:A")
CharToFind = "HI"
Set RgDestination = ActiveWorkbook.Worksheets(2).Range("A65536") _
.End(xlUp).Offset(1, 0).EntireRow
Set rg = FindAll(CharToFind, RgToSearch, xlValues, xlWhole, True, False)
If Not rg Is Nothing Then
rg.EntireRow.Copy RgDestination
End If
End Sub
Public Function FindAll( _
What As Variant, _
Where As Range, _
Optional LookIn As XlFindLookIn = xlValues, _
Optional LookAt As XlLookAt = xlPart, _
Optional MatchCase As Boolean = False, _
Optional MatchByte As Boolean = False) As Range
Dim ResultRg As Range
Dim rg As Range
Dim firstAddress As String
With Where
Set rg = .Find(What, LookIn:=LookIn, LookAt:=LookAt, _
MatchCase:=MatchCase, MatchByte:=MatchByte)
If Not rg Is Nothing Then
Set ResultRg = rg
firstAddress = rg.Address
Do
Set ResultRg = Application.Union(ResultRg, rg)
Set rg = .FindNext(rg)
Loop While Not rg Is Nothing And rg.Address <> firstAddress
End If
End With
Set FindAll = ResultRg
End Function
|