Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 49892

color alternating rows

$
0
0
Hi to all,
this macro color alternate rows if column A is not empty.
Is it possible to modify "or even the B / C column" ?

Code:

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
  Dim bClr As Boolean
  Dim c As Range, rChanged As Range
  Dim cols As Long
 
  Const sRange As String = "A2:H500"
 
  Set rChanged = Intersect(Target, Range(sRange).Columns(1))
  If Not rChanged Is Nothing Then
    Application.ScreenUpdating = False
    With Range(sRange)
      .Interior.ColorIndex = xlNone
      cols = .Columns.Count
    End With
    For Each c In Range(sRange).Columns(1).Cells
      If c.Value <> vbNullString Then
        If bClr Then
          c.Resize(, cols).Interior.ColorIndex = 15
        End If
        bClr = Not bClr
      End If
    Next c
    Application.ScreenUpdating = True
  End If
  End Sub

thank you
xam

Viewing all articles
Browse latest Browse all 49892

Trending Articles