clear vba macro

John Caines

Well-known Member
Joined
Aug 28, 2006
Messages
1,155
Office Version
  1. 2019
Platform
  1. Windows
Hello All.
I'm tring to create a simple (Though not for me) :-)
Clear macro.

All I'm looking to do is just add 1 more line of code/text,,, and I'm not sure how to do it. :-(
So far the VBA I have is as follows;
Code:
Sub Clear_All_Data()
If WorksheetFunction.CountA(Range("E24:E274,H24:I274,J23:K274,O24:O274")) = 0 Then
    MsgBox "Sorry, No Data to Clear :-)"
Else
    If MsgBox("Are You Sure You Want To Delete ALL Your Entered Data?", vbYesNo + vbCritical) = vbYes Then
        Range("E24:E274,H24:I274,J23:K274,O24:O274").ClearContents
            MsgBox "All Your Entered Details Have Now Been Cleared",  vbInformation
        End If
    End If
End Sub

The line I would like to add is just after the line that says, " "Are You Sure You Want To Delete ALL Your Entered Data?"
IF they click NO,,, I would like to display another message that just says;
"No problem, nothing will be cleared."

Can anybody show me how this would be inserted please, I've tried a few attempts but just can't seem to get it right. ;-(

I hope the above makes sense.
many Thanks;
John Caines
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi John. Try

Code:
Sub Clear_All_Data()
If WorksheetFunction.CountA(Range("E24:E274,H24:I274,J23:K274,O24:O274")) = 0 Then
    MsgBox "Sorry, No Data to Clear :-)"
Else
    If MsgBox("Are You Sure You Want To Delete ALL Your Entered Data?", vbYesNo + vbCritical) = vbYes Then
        Range("E24:E274,H24:I274,J23:K274,O24:O274").ClearContents
        MsgBox "All Your Entered Details Have Now Been Cleared", vbInformation
    Else
        MsgBox "No problem, nothing will be cleared.", vbInformation
    End If
End If
End Sub
 
Upvote 0
<font face=Courier New>    <SPAN style="color:#00007F">If</SPAN> MsgBox("Are You Sure You Want To Delete ALL Your Entered Data?", vbYesNo + vbCritical) = vbYes <SPAN style="color:#00007F">Then</SPAN><br>            Range("E24:E274,H24:I274,J23:K274,O24:O274").ClearContents<br>                MsgBox "All Your Entered Details Have Now Been Cleared", vbInformation<br>    <SPAN style="color:#00007F">Else</SPAN><br>            MsgBox "No problem, nothing will be cleared."<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN></FONT>
 
Upvote 0
Hi VOG!,, & Repairman615,,,,
Great minds think alike!!!:-)

You've replied with both the same answers,, excellent.

Many thanks to you both for this,,, I couldn't get it,,, though now looking at your answers,, they seem very logical.

As a note,, I was trying,, things like;
Code:
Sub Clear_All_Data()
If WorksheetFunction.CountA(Range("E24:E274,H24:I274,J23:K274,O24:O274")) = 0 Then
    MsgBox "Sorry, No Data to Clear :-)"
Else
    If MsgBox("Are You Sure You Want To Delete ALL Your Entered Data?", vbYesNo + vbCritical) = vbNo Then
        MsgBox "No problem, nothing will be cleared." = vbYes Then
        Range("E24:E274,H24:I274,J23:K274,O24:O274").ClearContents
            MsgBox "All Your Entered Details Have Now Been Cleared", vbInformation
        End If
    End If
End Sub

Not quite eh, :-)

Just 1 more question if I may that you might have an answer for......
When a pop up does show, (For example,,"No Problem, nothing will be cleared."),, the top left of the pop up box,, (It's FRAME) says,"Microsoft Excel",,,,,,,,,,,,
Is there anyway to alter this so I can make it display say "Answer For No"

Just showing "Microsoft Excel" all the time is so generic,, and not that informative.
Just wondered if it could be altered that was all.
Again,,, many thanks to you both for your replies.

Best regards
john Caines
 
Upvote 0
Try like this

Code:
Sub Clear_All_Data()
If WorksheetFunction.CountA(Range("E24:E274,H24:I274,J23:K274,O24:O274")) = 0 Then
    MsgBox "Sorry, No Data to Clear :-)", vbInformation, "Nothing to clear"
Else
    If MsgBox("Are You Sure You Want To Delete ALL Your Entered Data?", vbYesNo + vbCritical, "Are you sure") = vbYes Then
        Range("E24:E274,H24:I274,J23:K274,O24:O274").ClearContents
        MsgBox "All Your Entered Details Have Now Been Cleared", vbInformation, "Entered data cleared"
    Else
        MsgBox "No problem, nothing will be cleared.", vbInformation, "Data retained"
    End If
End If
End Sub
 
Upvote 0
Excellent VOG!!!

Exactly what I was after,,,
this I can now implement on other spreadsheets/workbooks I have,,,


Great stuff.

Best regards VOG,,,,,
Mnay Thanks
John Caines
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top