PDA

View Full Version : Check if a shape is selected



jolivanes
06-26-2011, 12:32 PM
I have the following code for a command button on a userform


Private Sub CommandButton1_Click()
Set r = Selection
r.Interior.Color = rgb(75, 172, 198)
End Sub

Works great if a shape has been selected that needs to be colored.
If no shape was selected, and a cell is still selected, the cell gets colored.
This is not what I want.
How can I check if a Shape has been selected?
The shapes (40+ shapes) are all named with 7 letters and 1 or 2 digits (i.e. rndBall25)
Thanks and Regards.
John

Kenneth Hobs
06-26-2011, 12:47 PM
You could use Right for the Name or:
Private Sub CommandButton1_Click()
Dim r As Object
Set r = Selection
If TypeName(r) <> "Range" Then r.Interior.Color = RGB(75, 172, 198)
End Sub

jolivanes
06-26-2011, 01:45 PM
Thank you very much Kenneth.

That did it, as you of course knew.

Thanks and Regards
John