Button help!

  • Thread starter Thread starter alchy
  • Start date Start date
A

alchy

would like to add a small gfx object that looks like a button in my
spreadsheet.
When someone clicks on it i would like it to perform a function.In my
case to reset all data to 0.

How can i do this and also after they click it how would i add a
validation "are you sure you want to reset all data to 0?" as a
security measure so they don't delete by mistake?

Im very new to this but this is the only function i need to add to my
sheet to finish my project

Regards Alchy
 
You came to da right place, Alchy. You can assign pretty much any graphic,
image, WordArt, etc. After putting it on your sheet, right-click it, and
use "Assign Macro" to the macro you wish a click on the graphic to cause to
run.

In the macro, use something like:

Sub GraphicClicked()
Response = MsgBox("You REALLY wanna do this, bunky?", vbYesNo)
If Response = vbYes Then
MsgBox "Resetting to 0"
Else
MsgBox "Not resetting"
End If
End Sub
 
Alchy

Tools>Customize>Commands>Macros. Drag a smiley-face button to your Toolbar.

Copy/paste the code below to a general module in your workbook. Hit ALT + F11
to get to the Visual Basic Editor. View>Project Explorer. Left-click on your
workbook/project. Insert>Module. Paste in here.

ALT + F11 to go back to Excel.

Assign the macro to your button.

Sub DoTHings()

Msg = "Do You Want to Re_set all data to 0? Y/N" & Chr(13) _
& "If No, This Macro will End"
ans = MsgBox(Msg, vbQuestion + vbYesNoCancel)
Select Case ans
Case vbYes
ActiveSheet.UsedRange.Cells.Value = 0
Case vbNo
Exit Sub
Case vbCancel
Cancel = True
Exit Sub
End Select

End Sub

Gord Dibben XL2002
 
Back
Top