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

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?
 
M

Mike H

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
 
L

Lars-Åke Aspelin

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
 
P

Per Jessen

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
 
Top