Consulting

Results 1 to 4 of 4

Thread: Using a variable in conditional formating

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

    Using a variable in conditional formating

    My last row is always different and I would like to do a conditional formating on the last column based on the total of that column. However, I can't figure out how to get the conditional formating to work

    [VBA]Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, Formula1:=finalCell[/VBA]

    That is my code and finalCell is my variable.

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hi there,

    Kind of hard without seeing the rest of your code. Why use Selection? What is finalCell?

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Djblois
    My last row is always different and I would like to do a conditional formating on the last column based on the total of that column. However, I can't figure out how to get the conditional formating to work

    [vba]Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, Formula1:=finalCell[/vba]
    That is my code and finalCell is my variable.
    How about using a formula that calculates the last cell, maybe a dynamic range formula or something?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Looking at your previous post I see that FinalCell does just that.

    As such, yoiur code seems to work. The only thing I could think was to delete them first

    [vba]

    Selection.FormatConditions.Delete
    Selection.FormatConditions.Add Type:=xlCellValue, _
    Operator:=xlLess, _
    Formula1:=finalCell
    [/vba]

    What difficulty are you having with it?

Posting Permissions

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