How to Highlight Every Other ID in Excel
Visual Basic for Applications (VBA) is the perfect tool to use if you need to highlight every other ID in a Microsoft Excel spreadsheet. VBA is a programming language that gives you the ability to extend Excel. VBA works by running macros, step-by-step procedures written in Visual Basic. VBA is used when you might want to find an easier way to perform a mundane, repetitive task, or to perform some task that the UI does not seem to address such as highlighting every other row.
Instructions
-
-
1
Launch Microsoft Excel, click the "Developer" tab and click Visual Basic to start the VBA editor window. Click the "Insert" menu, and click "Module" to add a new code module. Add the following code to create a new sub procedure and two "Integer" variables:
Private Sub highlightRows()
Dim X As Integer
Dim Y As Integer
-
2
Populate the first ten rows of column A1 with "Integer" IDs using a "For...Loop:"
For X = 1 To 10
Range("A" & X).Select
Range("A" & X).Value = X
Next X
-
-
3
Highlight every other ID by using the following "For...Loop:"
For y = 1 To 10
Rows(y & ":" & y).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
y = y + 1
Next y
-
4
Type "End Sub" to end your procedure, and click "F5" to run it. Switch to the Microsoft Excel to view the results.
-
1
References
- Photo Credit Jason Reed/Photodisc/Getty Images