Consulting

Results 1 to 10 of 10

Thread: Solved: Coloring alternate rows

  1. #1

    Solved: Coloring alternate rows

    Hello
    This code works pretty well but there are two things I'd hope to fix...
    Range("A2:F19").Select
        Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=MOD( ROW( ), 2) =0"
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorLight2
            .TintAndShade = 0.799981688894314
        End With
        Selection.FormatConditions(1).StopIfTrue = True
    the first thing is it highlights the selection because of this bit
    Range("A2:F19").Select
    but it doesn't work without it.
    The 2nd item may fix the first and that is I would rather it be dynamic for the number of rows to color. The number of rows will change daily and want it to color where there is data.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [VBA] With Selection

    .FormatConditions.Add Type:=xlExpression, Formula1:="=MOD( ROW( ), 2) =0"
    .FormatConditions(.FormatConditions.Count).SetFirstPriority
    With .FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorLight2
    .TintAndShade = 0.799981688894314
    End With
    .FormatConditions(1).StopIfTrue = True
    End With[/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
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    To get from the second cell in A to the last cell in F automatically, add this befor xlds

    [VBA]Range("A2:F" & Range("F" & rows.count).End(xlUp).Row).Select[/VBA]
    ------------------------------------------------
    Happy Coding my friends

  4. #4
    This didn't color anything.
    With Selection
    .FormatConditions.Add Type:=xlExpression, Formula1:="=MOD( ROW( ), 2) =0" .FormatConditions(.FormatConditions.Count).SetFirstPriority With .FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorLight2 .TintAndShade = 0.799981688894314 End With .FormatConditions(1).StopIfTrue = True End With
    this helped...
    Range("A2:F" & Range("F" & rows.count).End(xlUp).Row).Select
    I added this..so it wouldn't highlight the whole area
    Range("A1").Select
    thanks guys for your input!!
    Last edited by Codeblue; 06-28-2012 at 12:41 PM.

  5. #5
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    did you add the select code before xld's code? it would only work if you had something selected...
    ------------------------------------------------
    Happy Coding my friends

  6. #6
    Yes, it's good now!

  7. #7
    VBAX Tutor lynnnow's Avatar
    Joined
    Jan 2005
    Location
    Mumbai, Maharashtra, India
    Posts
    299
    Location
    Remember to mark your thread Solved if you no longer need assistance on your post.

  8. #8
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    or

    [VBA]Sub snb()
    Cells(2, 5).CurrentRegion.Name = "codeblue"
    Range(Join(Filter([transpose(if(mod(row(codeblue),2)=0,"A" & row(codeblue),""))], "A"), ",")).EntireRow.Interior.ColorIndex = 16
    End Sub[/VBA]

  9. #9

    Solved -- Coloring alternate rows

    What is this last code for?

    Not sure how to mark this as solved

  10. #10
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    It's an alternative to get the same result.

Posting Permissions

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