Remove "-" from 01928455-01 - want 0192845501

Joined
Jul 27, 2007
Messages
8
Reaction score
0
I'd like to remove dashes from a string. I want to remove the "-" from 01928455-01 and replace it with 0192845501.

How can I achieve this in my macro. Can anyone help...
 
This Code removes a "-" from a String in a Cell and rejoins the parts on either side of the dash to return a value without the dash. Can be used to remove any character in a string. e.g. takes someting like this 90289374-01 and returns 9028937401. Note this process only removes one dash. Can bve modified to remove more dashes if reqiuired.

' Returns the position number of the dash in a string
vLocnDash = InStr(1, (Cells(vrow, 1)), "-", vbTextCompare)
' Establish the length of the string
vLenprodId = Len(Cells(vrow, 1))
' Calculate the number of postions right of the dash
vLenSecondPt = vLenprodId - vLocnDash
' If Dashes found (vLocnDash is zero when no dash is found)
If vLocnDash > 0 Then
' Establishing the number of positions left of the dash
vLenFirstPt = vLocnDash - 1
' Storing the characters left of the dash in FirstPart String
FirstPart = Left((Cells(vrow, 1)), vLenFirstPt)
' Storing the characters right of the dash in SecondPart string
SecondPart = Right((Cells(vrow, 1)), vLenSecondPt)
' Concatenating Firstpart & SecondPart to recreate the string without a dash
Cells(vrow, 1) = (FirstPart & SecondPart)
End If

This was how I was able to achieve what I needed.

Ted Broniecki answering his own question once again....
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top