+ Reply to Thread
Results 1 to 5 of 5

Select specif range on Conditional Format

Hybrid View

  1. #1
    Registered User
    Join Date
    05-04-2006
    Posts
    56

    Select specif range on Conditional Format

    Hi,
    I've managed to conditionally format a cell with VBA (im a vba noobie)
    What I really want to do is format a range of rows.
    Currently criteria from Column I and I want to color rows E to J.. I’m just not sure how to select the row. Is it Range.Select(), or Cell.Select() ?

    I've commented my poor attempt in the code to select the appropriate rows.
    Private Sub Worksheet_Calculate()
        Dim icolor As Integer
        For Each r In Range("I10:I30")
                With r
                    Select Case .Value
                        Case 0 To 0.69
                           'cells("E:J")
                            icolor = 10  'green
                        
                        Case 0.7 To 0.89
                            icolor = 44  'amber
                            'Range.Select ("E:J")
    Cheers
    Cam

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Cam

    Not sure I follow. If I10 is .5, do you want E10:H10 to be colored green?

    Is that what you want to do?

    rylo

  3. #3
    Registered User
    Join Date
    05-04-2006
    Posts
    56
    Hey Rylo,
    Absolutley correct!

    on another note when i enter a date somewhere i get a Compile Error on the code. It's slecting the first case (Case 0.1 To 0.69) in Yellow highlight. not sure whats happening????

    Complete Code:
    HTML Code: 

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Try

    Private Sub Worksheet_Calculate()
        Dim icolor As Integer
        For Each r In Range("I10:I30")
                icolor = xlNone
                With r
                    Select Case .Value
                        Case 0.1 To 0.69
                            icolor = 10  'green
                        Case 0.7 To 0.89
                            icolor = 44  'amber
                            'Range.Select ("E:J")
                        Case 0.9 To 0.99
                            icolor = 9  'red
                            'Range.Select ("E:J")
                        Case 1 To 1.01
                            icolor = 2  'white
                            'Range.Select ("E:J")
                        Case 1.02 To 99
                            icolor = 3  'red
                        Case Else
                            'Whatever
                    End Select
                Range("E" & r.Row & ":H" & r.Row).Interior.ColorIndex = icolor
                End With
        Next
    End Sub
    rylo

  5. #5
    Registered User
    Join Date
    05-04-2006
    Posts
    56
    Thanks Rylo! BIG HELP.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1