Highlighting every 3 row with VBA?

XcelNoobster

New Member
Joined
Jun 7, 2022
Messages
40
So I have a macro, that generates a sheet("Results") that contains the (A) location, sheet name, etc where an employee Id is found. And above each row(A), I also output the headers for the sheets where the Employee Id is found. I then give an extra row separating the next entry. How would I modify my macro so it highlights that extra row? The first entry(Header) start at row# 2, so row 4 should be highlighted.

VBA Code:
Sub findIDs2()

' findIDs2 Macro
' Once Parsed1 is run, run findIDs2 macro to output location and entire line where that Id is found.
'
    Application.ScreenUpdating = False
    Dim srcRng As Range, rng As Range, sAddr As String, fnd As Range, ws As Worksheet, x As Long: x = 2
    Dim rngWs As Range
    Dim y As Long: y = 1
    
    Set srcRng = Sheets("IDs").Range("A1", Sheets("IDs").Range("A" & Rows.Count).End(xlUp))
    
    Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Results"
    Sheets("Results").Activate
    Range("M1").Value = "Employee ID"
    Range("M1").Font.Color = vbRed
    Range("N1").Value = "Record Location"
    Range("N1").Font.Color = vbRed
    Range("O1").Value = "Record Sheet"
    Range("O1").Font.Color = vbRed
    
    
    
    
    
    
    For Each rng In srcRng
        For Each ws In Sheets
            If ws.Name <> "IDs" And ws.Name <> "Results" Then
                Set fnd = ws.Cells.Find(rng, LookIn:=xlValues, lookat:=xlPart)
                If Not fnd Is Nothing Then
                    sAddr = fnd.Address
                    Do
                        With Sheets("Results")
                        'Change x to x+1
                            .Columns.ColumnWidth = 20
                            .Range("M" & x + 1) = fnd
                            .Range("N" & x + 1) = fnd.Address
                            .Range("O" & x + 1) = ws.Name
                            'try add something like this use the row number that the headers are on
                        ws.Rows(1).EntireRow.Copy
                        .Range("A" & x).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
                         Set rngWs = Intersect(fnd.EntireRow, fnd.CurrentRegion)
                    rngWs.Copy
                     .Range("A" & x + 1).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
                    'Change to x+2 from x+1  + 3 ----> mihgt cause issue need to check
                    x = x + 3
                End With
                Set fnd = ws.Cells.FindNext(fnd)
            Loop While fnd.Address <> sAddr
                    sAddr = ""
                End If
            End If
        Next ws
    Next rng
    
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
This does what you asked, add this line here:
VBA Code:
'...
rngWs.Copy
.Range("A" & x + 1).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
.Range("A" & x + 2 & ":O" & x + 2).Interior.Color = 65535 '(yellow)       '<- added
'Change to x+2 from x+1  + 3 ----> mihgt cause issue need to check
x = x + 3
'...
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top