Consulting

Results 1 to 2 of 2

Thread: Use a dynamic range in a formula

  1. #1
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location

    Use a dynamic range in a formula

    I am using some code to band rows but now I am switching it to be dynamic. Here is the code I am trying but I cant figure out how to do it dynamically:

    [vba]With Range(Cells(lgStart, 1), Cells(finalrow(ActiveSheet), FinalColumn(ActiveSheet)))
    .FormatConditions.Add Type:=xlExpression, Formula1:="=AND(MOD(ROW(),2),COUNTA($A1:$H2))"
    .FormatConditions(.FormatConditions.Count).SetFirstPriority
    With .FormatConditions(1).Interior
    .ColorIndex = 34
    .StopIfTrue = False
    End With
    End With[/vba]
    I know how to do it in code but I cant do it in the formula portion. This portion I dont know how to make dynamic:

    [VBA]COUNTA($A1:$H2))[/VBA]

    I need to make it so the column can always be different
    Thank You,
    Daniel Blois
    http://studenthacker.blogspot.com/

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Is this what you mean Daniel?

    =COUNTA($A1:INDEX(2:2,COUNTA(1:1)))
    ____________________________________________
    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

Posting Permissions

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