Command button to clear cell contents

Rockhopper25

New Member
Joined
Aug 7, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi everyone

can anyone help me with this, im pretty sure it will have been asked before but i cannot find anything for it

i have a spreadsheet with several command buttons on that when i highlight a cell then click a button it fills that cell with a colour

what i also need is to be able to highlight any cell then click a button marked clear that will then clear the contents of that cell

i can do it by changing the colour to white but then it changes the surrounding cell borders to white as well which i do not want

could anyone help me with a code to set this up please


Regards Brian
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi & welcome to MrExcel.
You can use
VBA Code:
Selection.Clear
 
Upvote 0
Rather the change the .Interior.Color of a cell to white you could set the .Interior.ColorIndex to xlNone to leave the grid lines visible.
But the .Clear code that Fluff mentioned is fastest.
 
Upvote 0
Hi & welcome to MrExcel.
You can use
VBA Code:
Selection.Clear
Hi Fluff, thank you for quick reply

Im not sure i have this right but its not working i just get an error when i run script

Sub CommandButtonClear ()
Selection.Clear
End Sub


Regards Brian
 
Upvote 0
What error do you get?
 
Upvote 0

Forum statistics

Threads
1,214,535
Messages
6,120,090
Members
448,944
Latest member
sharmarick

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