Change Colour

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,062
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have the code below and just need to work it in correct way

this table below has the colour code in RGB it should fill the colour with respect to RGB , if the cell value is above 70 then RGB colour fill should be (0,176,80) and so on.

any help

1​
109.43​
RGB0,176,80Green color> 70
2​
105.826​
RGB146,208,80light green>55 - <=70
3​
103.195​
RGB255,0,0Red<55
5​
83.479​
6​
105.624​
7​
47.382​
8​
104.02​
9​
111.292​
10​
61.826​
11​
97.132​
12​
109.231​
13​
66.869​
14​
175.715​




VBA Code:
Sub fillcolor()

For I = 1 To 15
a = Sheet1.Cells(I + 1, 2) / 71 * 255
c = Sheet1.Cells(I + 1, 2) / 70 * 255
b = Sheet1.Cells(I + 1, 2) / 55 * 255

Sheet1.Shapes.Range(Array("Freeform " & I + 1)).Fill.ForeColor.RGB = RGB(a, c, b)
Next I


End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi can you help please.

This code workes all perfect
VBA Code:
Sub fillcolorSubsinthousands()
  Dim i As Long
  Dim a As Long
  Dim sRGB As String
  Dim vRGB As Variant
  
  'On Error Resume Next
  For i = 1 To 10
    Select Case Sheet5.Cells(i + 4, 7).Value
      Case Is < 0: sRGB = "255,0,0"
      Case Is > 0: sRGB = "0,176,80"
      Case Else: sRGB = "146,208,80"
    End Select
    vRGB = Split(sRGB, ",") '"146,208,80"
    'Sheet5.Shapes.Range(Array("TextBox" & i)).Fill.ForeColor.RGB = RGB(vRGB(0), vRGB(1), vRGB(2))
    Sheet5.Shapes.Range(Array("TextBox" & i)).TextFrame.Characters.Font.Color = RGB(vRGB(0), vRGB(1), vRGB(2))
    Next i
End Sub


But once i change the column ref from 7 to 11 code don't take the right colour
VBA Code:
Sub fillcolorSubsinthousands()
  Dim i As Long
  Dim a As Long
  Dim sRGB As String
  Dim vRGB As Variant
  
  'On Error Resume Next
  For i = 11 To 20  ''(Text box name is change from 11 to 20)
    Select Case Sheet5.Cells(i + 4, 11).Value ''' Here the column is changed
      Case Is < 0: sRGB = "255,0,0"
      Case Is > 0: sRGB = "0,176,80"
      Case Else: sRGB = "146,208,80"
    End Select
    vRGB = Split(sRGB, ",") '"146,208,80"
    Sheet5.Shapes.Range(Array("TextBox" & i)).TextFrame.Characters.Font.Color = RGB(vRGB(0), vRGB(1), vRGB(2))
   Next i
End Sub

1692878071145.png
 
Upvote 0
Can't see the column & row labels. In Sheet5, what is in G5:G14 and in K15:K24?
 
Upvote 0
1692885121165.png


This code is reading values from K15:K24 but there are no values in those cells.
 
Upvote 0
So if i want to pick the values from K5:K14, what change should be done. for textbox11 to textbox20 what change need to eb done
as textbox11 will pick up value from K5 and do the colour change and so on...
 
Upvote 0
So if i want to pick the values from K5:K14, what change should be done. for textbox11 to textbox20 what change need to eb done
as textbox11 will pick up value from K5 and do the colour change and so on...
Have you tried to work that out for yourself?

1692931514054.png

At the moment, the code starts at 11 and adds 4 (=15). That is why it reads the first value from row 15 (K15).
Instead of adding 4, what would you need to do to 11 to get the first value from row 5?
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,839
Members
449,193
Latest member
MikeVol

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