Consulting

Results 1 to 5 of 5

Thread: Solved: conditional formatting

  1. #1
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location

    Solved: conditional formatting

    hi,

    i'm running into an issue with the following code
    [vba]Sub test()
    With Sheets("total")
    Set c = .Range("H6", .Range("H" & Rows.Count).End(xlUp))
    End With
    Sheets.Add.Name = "A"
    c.Copy Sheets("A").Range("h6")
    With Sheets("A")
    .Columns("H:H").FormatConditions.Delete
    Set c = .Range("H1", .Range("H" & Rows.Count).End(xlUp))
    c.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=COUNTIF($H$1:H1,H1)>1"
    c.FormatConditions(1).Interior.ColorIndex = 35
    End With
    End Sub[/vba]

    when i check the Conditional Formatting in Sheets("A"), it shows as follows:
    =COUNTIF($H$1:O6,O6)>1

    it should be "=COUNTIF($H$1:H1,H1)>1

    how can i correct this?

    thanks
    zach

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

    Sub test()
    With Sheets("total")

    Set c = .Range("H6", .Range("H" & Rows.Count).End(xlUp))
    End With

    Sheets.Add.Name = "A"

    c.Copy Sheets("A").Range("h6")

    With Sheets("A")

    .Columns("H:H").FormatConditions.Delete
    Set c = .Range("H6", .Range("H" & .Rows.Count).End(xlUp))
    c.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=COUNTIF($H$1:" & ActiveCell.Address(False, False) & "," & ActiveCell.Address(False, False) & ")>1"
    c.FormatConditions(1).Interior.ColorIndex = 35
    End With
    End Sub
    [/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 Tutor
    Joined
    Feb 2006
    Posts
    295
    Location
    hi bob,

    thanks for the code. if you're not too busy, can you explain [VBA]ActiveCell.Address(False, False) & "," & ActiveCell.Address(False, False)[/VBA]

    thanks again
    zach

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Instead of entering the relative cell address H1 as you did, I enter the relative cell address of the active cell. This is because CF automatically adjusts a formula in relation to the activecell. You can do it tjhis way, or select H1 andd then use H1.
    ____________________________________________
    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

  5. #5
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location
    thanks for the explanation

    zach

Posting Permissions

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