VBA select group # from value in cell

PPriest

New Member
Joined
Jun 11, 2018
Messages
36
I am writing VBA code to refer to the group number in cell ("W5") of my worksheet. Instead of referring to ("Group 336") - I want to refer to the group using something along these lines: ("Group (Range("W5").Value)"):

Dim wsh As Worksheet: Set wsh = ActiveSheet
Dim shp As Shape: Set shp = wsh.Shapes("Group 336")
With shp.Fill
.ForeColor.RGB = RGB(255, 145, 0) ' Set the color
End With
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try this:
Code:
Sub Group_Shape()
'Modified 4/27/2019 6:58:23 PM  EDT
ActiveSheet.Shapes("Group " & Range("W5").Value).Fill.ForeColor.RGB = RGB(255, 145, 0)
End Sub
 
Upvote 0
Let's try this instead:
It provides some error catching in case you have no shape by that name.
Code:
Sub Group_Shape()
'Modified  4/27/2019  7:19:40 PM  EDT
On Error GoTo M
ActiveSheet.Shapes("Group " & Range("W5").Value).Fill.ForeColor.RGB = RGB(255, 145, 0)
Exit Sub
M:
MsgBox "We had a problem." & vbNewLine & "You may not have a shape by that name"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,135
Members
453,021
Latest member
Justyna P

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