Solved

Excel Command Button to Clear Sheet and Display Shapes

Posted on 2011-02-14
4
376 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
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…

896 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now