Clear specific cells using function & VBA? Haven't had success so far.

Beta Test Team

New Member
Joined
Sep 7, 2014
Messages
9
Hi forum, this is a great place! So far all of our questions have been answered here from searching your site without even having to register to post - impressive :). But now we're stuck. It's likely so simple advanced Excel users don't think twice about it: how to use the VBA code one can find on the Interents from the worksheet?

Here's what we want to do, but please suggest other options if this is not smart. Excel 2013 here. Thus far the workbook as no VBA:

- Use a function (IF?) combined with VBA to clear specific user input cells when a specific cell lists text (Y/N), on the same worksheet. So for example, cell A1, A2, and A4 are all cleared when cell A10 prints the text "Y."

- Can this be done without VBA? (I'm pretty sure not.)

- Otherwise, we have found VBA for this purpose but all the solutions we find lack enough context to enable us to use them.

- Bonus points if there's a method to use a click-able button, so a user clicks the button and the cells are cleared.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
a method to use a click-able button, so a user clicks the button and the cells are cleared

Put the code below in a regular module, put a forms button on the sheet, right click the button, click assign macro, select the Clearme macro.

Code:
Sub Clearme()
Range("A1:A2,A4").ClearContents
End Sub
 
Upvote 0
Shouldn't it be
Code:
Sub Clearme()
IF Range("A10").value = "Y" then Range("A1:A2,A4").ClearContents
End Sub
 
Upvote 0
My code was specifically in response to the quote below from the original question

- Bonus points if there's a method to use a click-able button, so a user clicks the button and the cells are cleared.

which I interpreted as being separate to the request for the cell have the "Y" entered in not as well as.
I could see no point having the button rather than just do it with event code when the "Y" was typed.
 
Upvote 0
Yep, fair enough....I read it the other way obviously......:beerchug:
 
Upvote 0
My code was specifically in response to the quote below from the original question

- Bonus points if there's a method to use a click-able button, so a user clicks the button and the cells are cleared.

which I interpreted as being separate to the request for the cell have the "Y" entered in not as well as.

I could see no point having the button rather than just do it with event code when the "Y" was typed.

You're correct Mark, that is what I wanted. The reason I want a button is to offer a different way of clearing the cells. So with the button a user can click it at any point to start over (there are lots of input cells), and the VBA that Micheal posted will be used to automatically clear all the input cells if a specific result is found in a specific helper cell after entering all the input data.

Sorry if I wasn't clear. Thanks again! :)
 
Last edited:
Upvote 0
Shouldn't it be
Code:
Sub Clearme()
IF Range("A10").value = "Y" then Range("A1:A2,A4").ClearContents
End Sub

Hello. Thanks for that, too :)

See what I wrote to Mark about use-cases. The VBA you posted will be very useful, and I can see how it can be edited to do other things, so it's a nice template for me to learn from.

Soon I'll be diving into the deep-ish end of VBA, so the more I can learn now the better. Cheers.
 
Upvote 0

Forum statistics

Threads
1,224,884
Messages
6,181,566
Members
453,053
Latest member
Kiranm13

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