Consulting

Results 1 to 3 of 3

Thread: Check if a shape is selected

  1. #1

    Check if a shape is selected

    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

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    You could use Right for the Name or:
    [VBA]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[/VBA]

  3. #3
    Thank you very much Kenneth.

    That did it, as you of course knew.

    Thanks and Regards
    John

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •