Message prompt in VBA

  • Thread starter Thread starter ltong
  • Start date Start date
L

ltong

Hi,

Please assist me on how to write an excel VBA code to prompt a message
" No sheet is to be delete, OK" instead of prompting a VBA error
message when I accidentally run a DeleteSheet macro, which had already
deleted all sheets in a workbook.

With this additional codes so that the DeleteSheet macro can be run
more smoothly.


Thanks
Regards
Lenard
 
Lenard,
I believe a workbook must have at least 1 worksheet. So
your sub could have something like:
If ThisWorkbook.Worksheets.Count > 1 Then
'run your deletesheets sub
Else
MsgBox prompt:="This worrkbook must have at least 1 sheet."
End If

Geof.
 
Hi all,

Frank, yes it is a msgbox and I got the VBA code from Geof

Thank you, Geof and it works.


By the way, I need another VBA code to prompt a message again " Sorry,
the selected sheet for deletion is not found, OK " ? and it ends the
VBA code instead of prompting VBA error .

Regards
Lenard
 

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