Skip to content

Instantly share code, notes, and snippets.

@misshie
Last active November 9, 2015 02:59
Show Gist options
  • Save misshie/730ea9e4c392fa608b4a to your computer and use it in GitHub Desktop.
Save misshie/730ea9e4c392fa608b4a to your computer and use it in GitHub Desktop.
An Excel VBA macro: Alterternate background of each row according to a key column (column C such as "chr1:123-123;A>T")
Sub PhysPosGrouping()
Dim oRange As Range
Dim lRorB As Long
Dim lColR As Long
Dim gcount As Long
Set oRange = ActiveSheet.UsedRange
lRowB = oRange.Row + oRange.Rows.Count - 1
lColR = oRange.Column + oRange.Columns.Count - 1
For Each e In Range("C2:C" & lRowB)
If e <> e.Offset(-1, 0) Then
gcount = gcount + 1
End If
If (gcount Mod 2) = 0 Then
e.EntireRow.Interior.ColorIndex = 15
Else
e.EntireRow.Interior.ColorIndex = 0
End If
Next e
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment