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
 

Some videos you may like

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,309
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
You can use
VBA Code:
Selection.Clear
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,920
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.
 

Rockhopper25

New Member
Joined
Aug 7, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,309
Office Version
  1. 365
Platform
  1. Windows
What error do you get?
 

Watch MrExcel Video

Forum statistics

Threads
1,123,341
Messages
5,601,063
Members
414,427
Latest member
fraru

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
Top