adjust macro for colors other than Excel 56 index colors

sunrise06

Active Member
Joined
Oct 27, 2006
Messages
264
Office Version
  1. 365
Platform
  1. Windows
Can someone tell me how to adjust this macro so I can use RGB colors and not required to use the 56 index colors?

Thanks!


Dim Shedule(100) As LectureBlock
Sub DrawShedule(b As Integer)
Dim LColor As Integer
Dim R As Range
Dim Str As String

With Shedule(b)
Select Case .Occupation
Case Is >= 0.5
Select Case .Occupation
Case Is <= 0.75
LColor = 35
Case Is <= 1
LColor = 36
Case Else
LColor = 22
End Select
Case Else
LColor = 37
End Select
Str = .Day & .Start & ":" & .Day & .End
Sheets("DISPLAY").Activate
Set R = Range(Str)
R.ColumnWidth = 18.09
R.RowHeight = 12
R.Merge
With R.Interior
.ColorIndex = LColor
.Pattern = xlSolid
End With
.....
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
If you're using Excel 2007+, then for example,

Code:
R.Interior.Color = RGB(redvalue, greenvalue, bluevalue)

If you're using Excel 2003-, then you can still use the Color property, but it will get mapped to the nearest color on the palette.
 
Upvote 0
Thank you shg but could you please be a little more specific? I have 4 LColor statements, based on on a specific condition, with the code at the bottom -
With R.Interior
.ColorIndex = LColor

Thanks!
 
Upvote 0
What colors do you want them to be?
 
Upvote 0
They will vary base on value. For example if Case Is <= 0.75 s/b RGB(174, 201, 87), and if Case Is <= 1 s/b RGB(217, 182, 93) etc...
 
Upvote 0
Code:
    Dim LColor      As [COLOR=red]Long[/COLOR]
 
    With Shedule(b)
        Select Case .Occupation
            Case Is >= 0.5
                Select Case .Occupation
                    Case Is <= 0.75
                        LColor = RGB(1, 2, 3)
                    Case Is <= 1
                        LColor = RGB(4, 5, 6)
                    Case Else
                        LColor = RGB(7, 8, 9)
                End Select
            Case Else
                LColor = RGB(10, 11, 12)
        End Select
 
        ...
 
         With R.Interior
            .Color = LColor
            .Pattern = xlSolid
        End With
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,304
Members
452,904
Latest member
CodeMasterX

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