VB Colours

wildturkey

Board Regular
Joined
Feb 21, 2006
Messages
189
Office Version
  1. 365
Platform
  1. Windows
Hi

I'm using the following to apply conditional formatting (picked up from an old thread) and it works great but the colours are pretty vivid and less transition from one colour to the next - not like the nice colour scale that conditional formatting offers. Is there any way to improve on this please - I've tried colorindex but no joy there...

VBA Code:
Sub ApplyCF()

    Dim UpperColour As Long, LowerColour As Long
    Dim StartRow As Long, EndRow As Long, CurrentRow As Long
    Dim StartColumn As Long, EndColumn As Long
    Dim Target As Range
   
    ' ******  Adjust as required  ******
   
    UpperColour = vbGreen
    LowerColour = vbWhite
   
    StartRow = 1
    EndRow = 3000
   
    StartColumn = 1
    EndColumn = 20
   
    ' **********************************
   
    For CurrentRow = StartRow To EndRow
   
        ' The Target range spans from the start column to the end column on iterative rows.
        Set Target = Range(Cells(CurrentRow, StartColumn), Cells(CurrentRow, EndColumn))
       
        ' Sets the conditional formatting rule for the range, Target
        With Target
            .FormatConditions.AddColorScale ColorScaleType:=2
            .FormatConditions(.FormatConditions.Count).SetFirstPriority
           
            ' Sets the colour for the lower value
            .FormatConditions(1).ColorScaleCriteria(1).Type = xlConditionValueLowestValue
            .FormatConditions(1).ColorScaleCriteria(1).FormatColor.Color = LowerColour
           
            ' Sets the colour for the upper value
            .FormatConditions(1).ColorScaleCriteria(2).Type = xlConditionValueHighestValue
            .FormatConditions(1).ColorScaleCriteria(2).FormatColor.Color = UpperColour
        End With
    Next
   
    MsgBox "Complete."
   
    Set Target = Nothing
   
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
You can use the RGB fuction to set the colors. This would set them to what they are currently, but you could massage them as desired.

VBA Code:
UpperColor = RGB(0, 255, 0) ' same as vbGreen
LowerColor = RGB(255, 255, 255) ' same as vbWhite
 
Upvote 0
Solution

Forum statistics

Threads
1,214,619
Messages
6,120,550
Members
448,970
Latest member
kennimack

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