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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,223,889
Messages
6,175,226
Members
452,620
Latest member
dsubash

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