Remove Hyphens From Multiple Strings

Buns1976

Board Regular
Joined
Feb 11, 2019
Messages
194
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone,
I have a single column(I) that currently contains 538 rows of UPC numbers(I1:I538). Each string of UPC numbers contains 3 hyphens(7-49504-3356-2).
I need to remove the hyphens if anyone has a solution for that I can run in a macro?

Thanks,
D
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Do you need a macro, or would a formula work?

VBA Code:
=TEXTJOIN(,,TEXTSPLIT(I1,"-"))

This formula removes the hypen and then joins the text without any delimiters.
 
Upvote 0
Supposing that only your data is in column I you could use this simple macro (or adjust as needed):
VBA Code:
Sub test()
    Range("I:I").Replace What:="-", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows
End Sub
 
Upvote 0
Supposing that only your data is in column I you could use this simple macro (or adjust as needed):
VBA Code:
Sub test()
    Range("I:I").Replace What:="-", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows
End Sub
Hey Rollis. Not sure why but I'm not getting any results on the code?
 
Upvote 0
VBA Code:
Sub test()
Range("I5:I538").Replace "-", ""
End Sub

Formula way:
=SUBSTITUTE(I5,"-","")
 
Upvote 0
Maybe your hyphen isn't so, maybe it's a en dash. Run this test and see what it returns.
VBA Code:
Sub test_char()
    MsgBox Asc(Left(Range("I5"), 2))
End Sub
 
Upvote 0
Maybe your hyphen isn't so, maybe it's a en dash. Run this test and see what it returns.
VBA Code:
Sub test_char()
    MsgBox Asc(Left(Range("I5"), 2))
End Sub
Doesn't that return the code of the first character in the string? Wouldn't it need to be ..
VBA Code:
MsgBox Asc(Mid(Range("I5"), 2))
 
Upvote 0
OMG, Thanks @Peter_SSs, you are right; it was very late last night :sleep: and I messed up the code :oops:.
 
Upvote 0
Do you need a macro, or would a formula work?

VBA Code:
=TEXTJOIN(,,TEXTSPLIT(I1,"-"))

This formula removes the hypen and then joins the text without any delimiters.
If I can find
Doesn't that return the code of the first character in the string? Wouldn't it need to be ..
VBA Code:
MsgBox Asc(Mid(Range("I5"), 2))
Sorry folks. I was pulled off on another project so been out of pocket for a few days. The code returned is 45 which reflects a hyphen if I'm not mistaken correct?
 
Upvote 0
Yes, that's it. At this point, please attach a sample of your data.
 
Upvote 0

Forum statistics

Threads
1,215,139
Messages
6,123,262
Members
449,093
Latest member
Vincent Khandagale

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