Consulting

Results 1 to 9 of 9

Thread: Highlighting every other row containing data

  1. #1
    VBAX Contributor
    Joined
    Oct 2013
    Posts
    181
    Location

    Highlighting every other row containing data

    I have search and cannot find a code or conditional formatting formula that will highlight every other row with multiple columns (A4:BB250) only if the rows contain data.

    Does anyone know of a way to do this?

    Thank you for your help

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Maybe something like this
    sub VBAX_SamT()
    dim r as long
    dim ColorMe as boolean
    dim WsF AS object
    set WsF = application.worksheet.function
    
    ColorMe = True 'to start with a highlighted row
    
    for r = 4 to 250' or 'To Cells(Rows.Count, "BB").End(xlUp).Row
    if WsF.Count(Rows.(r)) and ColorMe then ' Count? or CountA?
    range("A" & r & ":BB" & r). interior.colorIndex = 5 'Adjust color to suit
    ColorMe = not ColorMe
    end if
    next r
    end sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Contributor
    Joined
    Oct 2013
    Posts
    181
    Location
    SamT,

    Thank you a quick response.

    I get an error when I run the code "Application does not support this property or method" Also, I get an error on this line but they maybe related.
    Thank you again for your help

    WsF.Count(Rows.(r))ColorMe Then' Count? or CountA?

  4. #4
    Just remove dot from this line after worksheet
    Set WsF = application.worksheet.function
    And also remove dot from this line after rows
    If WsF.Count(Rows.(r)) And ColorMe Then ' Count? or CountA?

  5. #5
    May be (if you mean to color only the row if all cells in the same row has data)
    Sub Test()
        Dim r   As Long
        Dim WsF As Object
        
        Set WsF = Application.WorksheetFunction
         
        For r = 4 To 250
            If WsF.CountA(Rows(r)) = 54 Then
                Range("A" & r & ":BB" & r).Interior.ColorIndex = 5
            End If
        Next r
    End Sub

  6. #6
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I get an error when I run the code "Application does not support this property or method" Also, I get an error on this line
    With Property and Method errors, first, always look at the error line for typos, misspellings, missing or extra dots and other punctuation.

    With "A Without B" errors, check for missing and mismatched "End"s and "Next"s in the code around the error line
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by oam View Post
    I have search and cannot find a code or conditional formatting formula that will highlight every other row with multiple columns (A4:BB250) only if the rows contain data.

    Does anyone know of a way to do this?

    Thank you for your help
    =MOD(ROW(),2)=0
    ____________________________________________
    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

  8. #8
    VBAX Contributor
    Joined
    Oct 2013
    Posts
    181
    Location
    Thank you all for your help.

  9. #9
    XLD you did not read carefully requirement.

    Originally Posted by oam I have search and cannot find a code or conditional formatting formula that will highlight every other row with multiple columns (A4:BB250) only if the rows contain data.

    Quote Originally Posted by xld View Post
    =MOD(ROW(),2)=0

Posting Permissions

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