+ Reply to Thread
Results 1 to 5 of 5

Remove a shape with user selection

Hybrid View

jeff_kaufman Remove a shape with user... 07-03-2013, 12:23 PM
Norie Re: Remove a shape with user... 07-03-2013, 12:28 PM
jeff_kaufman Re: Remove a shape with user... 07-03-2013, 01:46 PM
jeff_kaufman Re: Remove a shape with user... 07-03-2013, 02:03 PM
Norie Re: Remove a shape with user... 07-03-2013, 02:06 PM
  1. #1
    Registered User
    Join Date
    06-04-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    54

    Remove a shape with user selection

    I have multiple buttons on a worksheet. Under some of the buttons is an oval or rectangular shape. When the user selects a button I am removing any text from the button and making the button not visible.

    I also want to delete the oval or rectangle shape that is at the location of the button.

    The following code runs and does not error out - everything works except it does not find the oval or rectangle in the range specified. Thoughts? Suggestions?

    Set r = ActiveSheet.Shapes(Application.Caller).TopLeftCell
            Set r2 = ActiveSheet.Shapes(Application.Caller).BottomRightCell
            
            ActiveSheet.Buttons(Application.Caller).Text = ""
            ActiveSheet.Shapes(Application.Caller).Visible = False
            
            Set rngDataArea = Range(Cells(r.Row, r.Column), Cells(r2.Row, r2.Column))
            
            For Each shpShape In ActiveSheet.Shapes
                If Not (Intersect(shpShape.TopLeftCell, rngDataArea) Is Nothing) _
                Then
                'Shape is in the data area to be cleared.
                    If shpShape.TextFrame.Characters.Text = "L/M" Or shpShape.TextFrame.Characters.Text = "EQUIP" Then
                        shpShape.Delete
                    End If
                End If
            Next shpShape

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Remove a shape with user selection

    Jeff

    Have you tried stepping through the code?

    Then you can see what's happening, or, in this case, not happening.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    06-04-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    54

    Re: Remove a shape with user selection

    I have stepped through it but I am not getting why the code is not picking up the shape. Could it be the range of cells it is looking in does not have the "topleftCell" of the shape in it?

  4. #4
    Registered User
    Join Date
    06-04-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    54

    Re: Remove a shape with user selection

    OKAY - the code above actually works. The if statement was not looking for the proper text (there were spaces in the text).... so idiot programmer mistake - sorry for the bother.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Remove a shape with user selection

    Jeff

    I actually thought that might be the problem but had no way to test.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1