Clear Content

Smurfit-Stone

Active Member
Joined
Dec 1, 2004
Messages
485
Hello Board,

I need a macro that will clear the content of multiple range names. I do not want to delete the range names, just clear the content in them. I need to clear a spreadsht daily to enter new data, there are 13 range names, that need to be cleared. Is there a easy way to do this? Thanks in advance.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
If you are talking about a VBA solution :-

Range(rangeName).ClearContents
 
Last edited:
Upvote 0
What are the names of the ranges, and when do you want them cleared? When the workbook opens? When the workbook is closed? At a specific time?
 
Upvote 0
I want to assign the macro to a button and let the user clear the content whenever their done with printing, emailing, etc. The range names are as follows.

Unit123
Unit122
Unit120
Unit104
Unit125
Unit128
Unit133
Unit135
Unit140
UnitSlitter
UnitWet
UnitDry
UnitPost
 
Upvote 0
Assign the following macro to your desired button:

Code:
Public Sub ClearRanges()
Range("Unit123", "Unit122", "Unit120", "Unit104", "Unit125", _
      "Unit128", "Unit133", "Unit135", "Unit140", "UnitSlitter", _
      "UnitWet", "UnitDry", "UnitPost").ClearContents
End Sub
 
Upvote 0
Thank You...it cleared the contents, but it gave me a error message that says "wrong number of arguments or invalid property assignments", what does this mean and what should I do? Thanks again!
 
Upvote 0
Add a button to the worksheet, either a Forms button or an ActiveX button (from the Control Toolbox.

For the Forms button, right click and select Assign Macro... and then click New.

You should see something like this:
Code:
Option Explicit
 
Sub Button1_Click()
 
End Sub
Note, some versions of VBA will go straight to the Assign macro part as soon as you add the button.

For the ActiveX button, double click it.

You should now see something like this:

Code:
Option Explicit
 
Private Sub CommandButton1_Click()
 
End Sub

Now for whatever type of button you've added, add this code.
Code:
Dim arrRanges
    arrRanges = Array("Unit123", "Unit122", "Unit120", "Unit104", "Unit125", "Unit128", "Unit133", _
                            "Unit135", "Unit140", "UnitSlitter", "UnitWet", "UnitDry", "UnitPost")
    
    Range(Join(arrRanges, ",")).ClearContents
You can make changes to the array, eg add names, change names, as needed.
 
Upvote 0
Assign the following macro to your desired button:

Code:
Public Sub ClearRanges()
Range("Unit123", "Unit122", "Unit120", "Unit104", "Unit125", _
      "Unit128", "Unit133", "Unit135", "Unit140", "UnitSlitter", _
      "UnitWet", "UnitDry", "UnitPost").ClearContents
End Sub


I think that should probably be :-

Range("Unit123, Unit122, Unit120, Unit104, Unit125, _
Unit128, Unit133,Unit135, Unit140, UnitSlitter, _
UnitWet, UnitDry, UnitPost").ClearContents
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,520
Members
452,923
Latest member
JackiG

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