Changing the color transparency of a cell

rcg78

New Member
Joined
Dec 12, 2014
Messages
6
I have written code to change the color of a cell based on whether the value of the cell is positive/negative. I would also like to change the transparency of that color (so the color is less intense). Does anyone know a quick way to add this change to my code? Or could someone help me write the code needed? Thanks!

Here is what I have so far...


'Color Cells


Dim i As Integer, j As Integer


For i = 2 To 23
For j = 3 To 21
If Worksheets("Calculations").Cells(i, j).Value > 0 Then
Worksheets("Calculations").Cells(i, j).Interior.ColorIndex = 50
Else: Worksheets("Calculations").Cells(i, j).Interior.ColorIndex = 3
End If
Next j
Next i
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
.
.

Try using the theme colors. Then you can adjust the TintAndShade property as needed:

Code:
Sub ColorCells()

    Dim i As Integer, j As Integer
    
    For i = 2 To 23
        For j = 3 To 21
            With Worksheets("Calculations").Cells(i, j)
                If .Value > 0 Then
                    .Interior.ThemeColor = xlThemeColorAccent3
                    .Interior.TintAndShade = 0.6
                Else
                    .Interior.ThemeColor = xlThemeColorAccent2
                    .Interior.TintAndShade = 0.6
                End If
            End With
        Next j
    Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,301
Members
449,078
Latest member
nonnakkong

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