Hello Becks7,
I added the following macro to the attached workbook. The macro has been expanded to allow the user to choose if case is to be ignored in the search. A check box has been added for this purpose.
Private Sub CommandButton1_Click()
Call FindText
End Sub
Sub FindText()
Dim Cell As Range
Dim ChkBox As Object
Dim DstWks As Worksheet
Dim I As Long
Dim LastRow As Long
Dim R As Long
Dim Rng As Range
Dim StartRow As Long
Dim TxtBox As Object
Set DstWks = Worksheets("Search")
'Find the Next Row and set object variables
With DstWks
StartRow = 7
R = .Cells(.Rows.Count, "A").End(xlUp).Row
R = IIf(R < StartRow, StartRow, R + 1)
Set TxtBox = .OLEObjects("SearchText").Object
Set ChkBox = .OLEObjects("CheckBox1").Object
End With
'Define the Search Range
With Worksheets("Sheet1")
StartRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
LastRow = IIf(LastRow < StartRow, StartRow, LastRow)
Set Rng = .Range(.Cells(StartRow, "A"), .Cells(LastRow, "B"))
End With
'Compare the Cell Text to the TextBox Text and copy any matches
For Each Cell In Rng
I = Cell.Row - StartRow + 1
Select Case ChkBox.Value
Case False
If Cell.Text Like TxtBox.Value Then
Rng.Rows(I).EntireRow.Copy DstWks.Cells(R, "A")
R = R + 1
End If
Case True
If LCase(Cell.Text) Like LCase(TxtBox.Value) Then
Rng.Rows(I).EntireRow.Copy DstWks.Cells(R, "A")
R = R + 1
End If
End Select
Next Cell
End Sub
Sincerely,
Leith Ross
Bookmarks