TaskMaster
Board Regular
- Joined
- Oct 15, 2020
- Messages
- 75
- Office Version
- 365
- 2016
- Platform
- Windows
Hi all I have the following that sequentially searches for FB09 and copies the data to another tab, I would like the row of the data being copied to be highlighted a colour as a check to tell me that data has being picked up. Is there a way to tweak this to do this?
VBA Code:
Sub FindAndCopyM()
Dim WS1 As Worksheet, WS2 As Worksheet
Dim R As Range, SearchRange As Range
Dim S As String, SearchStr As String ,FirstAddr As String
Dim LastRow As Long
Dim FirstPass As Boolean
Set WS1 = Worksheets("data")
Set WS2 = Worksheets("summary")
SearchStr = "FB09"
Set SearchRange = WS1.Range("S1", WS1.Range("S" & WS1.Rows.Count).End(xlUp))
With SearchRange
Set R = .Find(what:=SearchStr, after:=.Cells(.Cells.Count), lookat:=xlPart, MatchCase:=True, searchdirection:=xlNext)
End With
If Not R Is Nothing Then
FirstAddr = R.Address
FirstPass = True
End If
Do While Not R Is Nothing
If Not FirstPass Then
Set R = SearchRange.Find(what:=SearchStr, after:=R, lookat:=xlPart, MatchCase:=True, searchdirection:=xlNext)
End If
If Not FirstPass Then
If R.Address = FirstAddr Then
Set R = Nothing
Exit Do
End If
Else
FirstPass = False
End If
If Not R Is Nothing Then
If InStr(R.Value, SearchStr) = 1 Then
S = Right(R.Value, 8)
If WS2.Range("A23").Value = "" Then
WS2.Range("A23").NumberFormat = "@"
WS2.Range("A23").Value = S
Else
With WS2
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A" & LastRow + 1).NumberFormat = "@"
.Range("A" & LastRow + 1).Value = S
End With
End If
End If
End If
Loop
End Sub