Consulting

Results 1 to 3 of 3

Thread: Color Banding Rows

  1. #1
    VBAX Regular
    Joined
    Jul 2010
    Posts
    9
    Location

    Color Banding Rows

    I'm getting run-time error '1004':application-defined or object defined error for this line of code: 'If R.EntireRow.Cells(1, DataTestColumn).Value <> vbNullString Then' Full code below.

    This FormatCellFill macro starts in cell A4 colorbanding every other 30 rows of groupings of data until it gets to a blank row then it restarts such that the last color banding will be less then 30. Any ideas as to what is wrong with the code?
    Thanks Evan

    [VBA]Sub FormatCellFill()
    Dim R As Range
    Dim LastRow As Long
    Dim ColorIndex As Long
    Dim InFill As Boolean
    Dim N As Long
    Dim ColorWidthColumns As Long
    Dim StartCell As String
    Dim DataTestColumn As String

    ColorIndex = 8 'cyan '<<<<<< Set color index
    InFill = True '<<<<< True -> Color first group, False-> No color first group
    ColorWidthColumns = 10 '<<<< how many columns wide to format
    StartCell = "A4" '<<<< where to start the banding
    DataTestRow = 4 '<<<< column number containing data to test
    Set R = Range(StartCell)
    With R.Worksheet
    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With
    N = 0
    Do Until R.Row > LastRow
    N = N + 1
    If R.EntireRow.Cells(1, DataTestColumn).Value <> vbNullString Then
    If InFill = True Then
    R.EntireRow.Cells(1, "A").Resize(, ColorWidthColumns).Interior.ColorIndex = ColorIndex
    Else
    R.EntireRow.Cells(1, "A").Resize(, ColorWidthColumns).Interior.ColorIndex = xlColorIndexNone
    End If
    Else
    N = 0
    InFill = True
    End If
    If N >= 30 Then
    N = 0
    InFill = Not InFill
    End If
    Set R = R(2, 1)
    Loop
    End Sub[/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Maybe try

    [vba]

    If R.EntireRow.Cells(1, DataTestColumn).Value <> "" Then
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    TestDataColumn = ""

    Cells(1, "") is an error

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •