Selecting a dynamic range and coloring it.......

nynamyna

New Member
Joined
Jul 12, 2009
Messages
34
Hello everybody,

I have an excel sheet in which there are seven columns. I will sort them using different combinations of criteria1 column and criteria2 column and give different colors to them. For example

criteria1 criteria 2 color
1 1 yellow
1 0 green
0 1 pink
0 0 blank

I recorded this as as a macro but, selecting the ranges for coloring becomes fixed. So if the file has more values then it is coloring only half of it. So this coloring should be done dynamically. Can anyone help ?

Thanks,
Bharath
<!-- / message --><!-- attachments -->
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
This is one way to do it:
Code:
Sub ColorA1CurrentRegion()

    Dim rngCell As Range
    Dim iCriterion1 As Integer
    Dim iCriterion2 As Integer
    
    For Each rngCell In Range("A1").CurrentRegion
        
        'Determine cell criteria values
        If rngCell.Value > 3 Then iCriterion1 = 1 Else iCriterion1 = 0
        If rngCell.Value = 2 Or rngCell.Value = 9 Then iCriterion2 = 2 Else iCriterion2 = 0
        
        'Modify for headers
        If Not IsNumeric(rngCell.Value) Then
            iCriterion1 = 0
            iCriterion2 = 0
        End If
        
        Select Case iCriterion1 + iCriterion2
        Case 0: rngCell.Interior.Color = vbWhite
        Case 1: rngCell.Interior.Color = vbRed
        Case 2: rngCell.Interior.Color = vbGreen
        Case 3: rngCell.Interior.Color = vbYellow
        End Select
    Next
    
End Sub
If your columns do not contain A1 then the address in the For statement must be changed to an appropriate value.
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,242
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top