Is there away I can but a button or something like that

rcirone

Active Member
Joined
Mar 12, 2009
Messages
483
Office Version
  1. 365
Platform
  1. Windows
Is there away I can but a button or something like that. That when press it will clear all content for a lot of cell but they are not all in the same row
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
You can create a button to run any VBA procedure that you create.
All you have to do is create your VBA procedure, and then assign that procedure to a command button (see How To Add A Form Control Button To Run Your VBA Code | How To Excel).

As for creating the VBA code, if you need help with that, you will need to provide a lot more details than you have!
I need A4:Q40 and x4:x40 , cells Y4, c154 to c166 I need all the cell I listed to clear all content when I hit the button.

Thanks for your help
 
Upvote 0
Pretty straightforward procedure.
VBA Code:
Sub MyClearCells()
    Range("A4:Q40").ClearContents
    Range("X4:X40").ClearContents
    Range("Y4").ClearContents
    Range("C154:C166").ClearContents
End Sub
If you need to make changes to it, it should be pretty easy to see how to do that.
 
Upvote 0
Solution
You could also do it in one line, like this:
VBA Code:
Sub MyClearCells2()
    Range("A4:Q40, X4:X40, Y4:Y4, C154:C156").ClearContents
End Sub
 
Upvote 0
Pretty straightforward procedure.
VBA Code:
Sub MyClearCells()
    Range("A4:Q40").ClearContents
    Range("X4:X40").ClearContents
    Range("Y4").ClearContents
    Range("C154:C166").ClearContents
End Sub
If you need to make changes to it, it should be pretty easy to see how to do that.
Thanks it works
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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