VBA - Remove all except numbers

PaulMacF

New Member
Joined
Mar 6, 2023
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hi there,

Realise this has been asked on here many times, but can't find a suitable solution for exactly what I need all the same -

Simply need to...
1/Remove everything except numbers from columns E:F
2/Fill any blank/empty cells in columns E:F with zeros's(0)
Needs to work down to the last populated row, no lower than that.

Thanks.
 

Attachments

  • mexcel4.PNG
    mexcel4.PNG
    24 KB · Views: 8

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Here is a formula that may help:

Question.xlsx
EFGHI
111141114
2134+3R1343
31352k1352
413411341
5606
6T660
Sheet8
Cell Formulas
RangeFormula
H1:I6H1=MAP(FILTER(E:F,E:E&F:F<>""),LAMBDA(x,0+(0&CONCAT(IFERROR(--MID(x,SEQUENCE(LEN(x)),1),"")))))
Dynamic array formulas.
 
Upvote 0
VBA Code:
=MAP(YourDataRangeHere,LAMBDA(x,TEXTJOIN("",TRUE,IFERROR(--MID(x,SEQUENCE(10),1),""))*1))
 
Upvote 0
Hi,
You can test following macro
VBA Code:
Sub LoopThroughRange()
Dim rng As Range, c As Range
Dim i As Integer
' Adjust to your specific Range
Set rng = Range("E4:F10")
For Each c In rng
    For i = 1 To Len(c.Value)
        If Asc(Mid(c.Value, i, 1)) < 48 Or Asc(Mid(c.Value, i, 1)) > 57 Then
            c.Value = Replace(c.Value, Mid(c.Value, i, 1), "")
        End If
    Next i
Next c
End Sub
 
Upvote 0
Thanks, couldn't get those to work. This did the trick.

VBA Code:
Sub RemoveNotNum()
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "RemoveText"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
    xOut = ""
    For i = 1 To Len(Rng.Value)
        xTemp = Mid(Rng.Value, i, 1)
        If xTemp Like "[0-9]" Then
            xStr = xTemp
        Else
            xStr = ""
        End If
        xOut = xOut & xStr
    Next i
    Rng.Value = xOut
Next
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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