![]() |
macro to ask yes/no question and continue based on answer
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? |
macro to ask yes/no question and continue based on answer
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 "JasonP CCTM LV" wrote: 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? |
macro to ask yes/no question and continue based on answer
On Fri, 18 Jul 2008 12:23:01 -0700, JasonP CCTM LV <JasonP CCTM
wrote: 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 |
macro to ask yes/no question and continue based on answer
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 "JasonP CCTM LV" <JasonP CCTM skrev i meddelelsen ... 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? |
macro to ask yes/no question and continue based on answer
Thanks. Your response, as well as Per Jessen's works perfectly.
"Mike H" wrote: 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 "JasonP CCTM LV" wrote: 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? |
macro to ask yes/no question and continue based on answer
Thanks. Your solution, like Mike H's, works perfectly.
"Per Jessen" wrote: 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 "JasonP CCTM LV" <JasonP CCTM skrev i meddelelsen ... 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? |
All times are GMT +1. The time now is 10:01 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com