Solved

Excel Command Button to Clear Sheet and Display Shapes

Posted on 2011-02-14
4
378 Views
Last Modified: 2012-05-11
Many thanks to rorya for his awesome skill in providing this UDF!!!  I've tried to create a command button to clear the shapes and call the function, but have been unsuccessful.  I would greatly appreciate an example with instructions on how to use a command button to call this function and display my shapes. cmdbtnEE.xlsm
0
Comment
Question by:asc2010
  • 2
  • 2
4 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 34889028
You don't need a button - you just need to move the function code from the worksheet module into a normal module in the workbook. It automatically creates and deletes shapes as required.
0
 

Author Comment

by:asc2010
ID: 34889094
My spreadsheet does not delete the shapes after the percentage is changed.  I moved the function back into the module as suggested.  Do I need to change something else? cmdbtnEE.xlsm
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 34889267
As I recall, my original code named the shapes (or do I misremember?). Delete all the shapes (f5, Special... button, select Objects, then press Delete), then replace the code with this:
Function ShowStatus(rng As Range)
   Dim shp1 As Shape, shp2 As Shape
   Dim wks As Worksheet
   Dim rngCell As Range
   Set rngCell = Application.Caller
   Set wks = rngCell.Worksheet
   On Error Resume Next
   With wks
      .Shapes("ProgBar" & Application.Caller.Address & "_1").Delete
      .Shapes("ProgBar" & Application.Caller.Address & "_2").Delete
   End With
   With rngCell
      'Set shp2 = wks.Shapes.AddShape(msoShapeRectangle, .Left, .Top, 100, .Height)
      'Set shp1 = wks.Shapes.AddShape(msoShapeRectangle, .Left, .Top, rng.Value * 100, .Height)
      Set shp2 = wks.Shapes.AddShape(msoShapeRoundedRectangle, .Left, .Top, 100, .Height)
      shp2.Name = "ProgBar" & Application.Caller.Address & "_2"
      Set shp1 = wks.Shapes.AddShape(msoShapeRoundedRectangle, .Left, .Top, rng.Value * 100, .Height)
      shp1.Name = "ProgBar" & Application.Caller.Address & "_1"
      shp1.Fill.ForeColor.SchemeColor = 7
   End With
End Function

Open in new window

0
 

Author Closing Comment

by:asc2010
ID: 34889349
rorya,

Thank you so much for clarifying this!! I noticed the with statement that deletes the shapes.  I thought it was not working because I moved the shapes away from their original position.  Once moved, they remain on the sheet.  I will leave them in place! Thanks again!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question