Delete cell contents if the cell contains numerical value

wurble86

New Member
Joined
Oct 8, 2013
Messages
4
Hi there

I am a VBA newbie. Recently I have been practising writing my own macros in VBA. I am using Excel 2010.

I have been trying to write a macro to look at two columns in a worksheet (say, columns D and E) and to delete the contents (not the formatting, and I don't want to delete the cell itself) of that cell only if it contains a numerical value (e.g. 1, 2, 256 or any other number). If it finds a cell with letters, then it wouldn't delete the contents of the cell. The cells are currently formatted as "currency" cells.

Can anyone please help me with the code I'd need? I have been trying all sorts of things and I just can't get it to work. I can write a macro to clear a range easy enough, but I am stuck on getting it to delete the right stuff. I won't embarrass myself by uploading the code that I have been using...

Thanks in advance, Adam :biggrin:
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi Adam
Welcome to the board

Are those number values the result of a formula or are they constants (or both)?
 
Upvote 0
Hi pgc01!

Thanks for the welcome.

These numbers have been manually input by a user - e.g. someone has typed them into the cells . They are not the results of formulas.

Hope that clears things up! :)
 
Upvote 0
Hi pgc01!

Thanks for the welcome.

These numbers have been manually input by a user - e.g. someone has typed them into the cells . They are not the results of formulas.

Hope that clears things up! :)

OK.

Try:

Code:
Sub Test()

On Error Resume Next
Columns("D:E").SpecialCells(xlCellTypeConstants, xlNumbers).ClearContents
On Error GoTo 0

End Sub
 
Upvote 0
OK.

Try:

Code:
Sub Test()

On Error Resume Next
Columns("D:E").SpecialCells(xlCellTypeConstants, xlNumbers).ClearContents
On Error GoTo 0

End Sub

pgc01,

Thank you SOO much from saving me from my pit of failure. It worked perfectly!

I can't believe that I spent so long trying to figure that out, and in the end the code looks so simple.

Thanks again!
 
Upvote 0
OK.

Try:

Code:
Sub Test()

On Error Resume Next
Columns("D:E").SpecialCells(xlCellTypeConstants, xlNumbers).ClearContents
On Error GoTo 0

End Sub
You HAve No IDEA how much work you saved me..... Thanks LOADS!!!
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,842
Members
449,193
Latest member
MikeVol

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