Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Remove numbers in string?

0

Hello,

I was wondering how i can remove numbers

Some names has a number in it

Like:

John 1Doe
John 1 Doe
1 John Doe
John Doe 1
John 1

I can't say where the number will be

StrConv(Trim(ws1.Range("N" & ResultRow).Value), vbUpperCase)

So i want to remove it from N

Is this possible?

Thank you

Answer
Discuss

Answers

0
Selected Answer

Hi again Ghost

You could loop through the string and only add only characters which aren't numbers.

I think you'll understand this code (and just need to replace Selection with your target cell and Debug.Print with where you want to put the string LessNo).:

Sub RemoveNumbers()

    Dim n As Long, LessNo As String

    With Selection
        For n = 1 To Len(.Value)
            If Not Mid(.Value, n, 1) Like "[0-9]" Then
                LessNo = LessNo & Mid(.Value, n, 1)
            End If
        Next n
    Debug.Print LessNo

    End With

End Sub

Hope this helps.

Discuss

Discussion

Hi John_Ru,
Thank you :)
GhostofWanted (rep: 46) Oct 26, '23 at 4:16 am
Thanks for selecting my Answer, Ghost. 
John_Ru (rep: 6142) Oct 26, '23 at 5:44 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login