VBA Code to Clear Cell

ERed1

Board Regular
Joined
Jun 26, 2019
Messages
104
Hi all,

I am trying to write a VBA code that will search the column and clear are cell with a specific value. For example, it will search column B for a cell containing the number "1". If it finds a cell contain "1", then that cell gets its contents cleared. I don't want it deleted so other columns and cells don't shift.

Thanks in advance for the help.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Do you want to clear all cells with 1?
 
Upvote 0
Forgot to ask if the numbers are hard values, or formulae.
If hard values try
Code:
Sub ERed1()
   Range("B:B").Replace 1, "", xlWhole, , , , False, False
End Sub
 
Upvote 0
It threw an error code. In my actual sheet, I am having column AD format to a date. The date for some of the cells is "1/0/1900". When I changed 1 in the code to the date, it still did not work.
 
Upvote 0
What was the error code & message?
 
Upvote 0
Assuming you have formatted the cell as m/d/yyyy then your cells contain 0 not 1
 
Upvote 0

Forum statistics

Threads
1,214,893
Messages
6,122,121
Members
449,066
Latest member
Andyg666

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