VBA Replace number with ""

sachavez

Active Member
Joined
May 22, 2009
Messages
469
Is there a way to replace numbers with blanks.

Example:

.replace what:="number", replacement:=""

I want to replace all numbers....

Thanks!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
One way is to loop through the range that you want to apply this to, and check to see if the entry is numeric with the IsNumeric function, i.e.
Code:
Sub MyReplace()

    Dim rng As Range
    Dim cell As Range
    
    Application.ScreenUpdating = False
    
'   Set range to apply this to
    Set rng = Range("A1:C5")
    
'   Loop through all cells in range
    For Each cell In rng
        If IsNumeric(cell) Then cell.ClearContents
    Next cell
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Does this clear the entire cell? I have other contents in the cell that I'd like to keep. Just want the numbers out.

Thanks!


One way is to loop through the range that you want to apply this to, and check to see if the entry is numeric with the IsNumeric function, i.e.
Code:
Sub MyReplace()

    Dim rng As Range
    Dim cell As Range
    
    Application.ScreenUpdating = False
    
'   Set range to apply this to
    Set rng = Range("A1:C5")
    
'   Loop through all cells in range
    For Each cell In rng
        If IsNumeric(cell) Then cell.ClearContents
    Next cell
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Is there a way to replace numbers with blanks.

Example:

.replace what:="number", replacement:=""

I want to replace all numbers....

Thanks!
Does ALL numbers include numbers returned by formulas or just numeric constants? If formulas are included do you want to replace the formulas with blanks?
 
Upvote 0
for clarity, I'd like to keep all non-number text in each cell. Just want the numbers gone.

Is there a way to replace numbers with blanks.

Example:

.replace what:="number", replacement:=""

I want to replace all numbers....

Thanks!
 
Upvote 0
I ended up writing ten of these:

.replace what:="0", replacement:=""

one for each number. It worked.
 
Upvote 0
What exactly do your entries look like?

Your question was rather ambiguous, and it is not clear to me if you just want to clear cells that are ALL NUMERIC, or you may have entries like "AB123XY" and you want to replace just the numbers so that you are left with "ABXY".
 
Upvote 0
I am assuming that you want to replace the numbers in mixed entries, like "AB123XY" (since my original code did not seem to work for you), here is some code that will instead of having to write out 10 replacement commands, will loop through all 10 numbers.
Code:
Sub MyReplaceNums()

    Dim rng As Range
    Dim cell As Range
    Dim nums As String
    Dim rep As String
    Dim i As Long
    
    Application.ScreenUpdating = False
    
'   Set values to replace
    nums = "0123456789"
    
'   Set range to do replacements
    Set rng = Range("A1:A10")
    
'   Loop through all cells in range
    For Each cell In rng
'       Loop through all numbers
        For i = 1 To Len(nums)
'           Get number to replace
            rep = Mid(nums, i, 1)
'           Do replacement
            With cell
                .Replace what:=rep, replacement:=""
            End With
        Next i
    Next cell
    
    Application.ScreenUpdating = True
    
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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