jeudi 22 octobre 2015

VBA If..Then Loop to Highlight Rows

I've got a little code that loops through a large amount of data and copies any row containing the phrase "Flowing" in column B, and pastes that row it on another worksheet. The code is the following:

Sub HighlightFlowingIntervals()

Worksheets("3901").Activate

Dim i As Long
Dim cell As Range
Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets("3901")
Dim ws2 As Worksheet: Set ws2 = ThisWorkbook.Sheets("Sheet2")

For i = 6 To ws1.Range("C17300").End(xlUp).Row
    If ws1.Cells(i, "B").Value = "Flowing" Then ws1.Rows(i).Copy ws2.Rows(ws2.Cells(ws2.Rows.Count, 2).End(xlUp).Row + 1)
Next i

End Sub

I now want to use the same structure of the loop, but instead of copying and pasting each row, simply highlight each row that passes the If..Then criteria. I know how to highlight using macro recorder, but don't want to do that unless I have to. I'm just not sure how to implement highlighting into the loop.

Any advice would be greatly appreciate. Thanks!

Aucun commentaire:

Enregistrer un commentaire