macro to ask yes/no question and continue based on answer

  • Thread starter Thread starter JasonP CCTM LV
  • Start date Start date
J

JasonP CCTM LV

I am setting up a macro in excel 2007. Is it possible to get excel to ask me
if I want to delete a specific column with a yes or no selection and have it
delete if I say yes or dont delete if I say no?
 
Try this

Sub askMe()
response = MsgBox("Delete selected column?", vbYesNo)
If response = vbYes Then
If Selection.Columns.Count < 2 Then
Selection.EntireColumn.Delete
Else
MsgBox "More than 1 column selected"
End If
End If
End Sub

Mike
 
On Fri, 18 Jul 2008 12:23:01 -0700, JasonP CCTM LV <JasonP CCTM
I am setting up a macro in excel 2007. Is it possible to get excel to ask me
if I want to delete a specific column with a yes or no selection and have it
delete if I say yes or dont delete if I say no?


Yes it is. Take a look at the MsgBox Function in the help.

Lars-Åke
 
Hi

Sub ColToDelete()
TargetCol = "D"
msg = MsgBox("Do you want to delete column " & TargetCol & " ?", vbYesNo)
If msg = vbYes Then Columns(TargetCol).Delete
End Sub

Regards,
Per
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top