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
 
Yes, that's it. At this point, please attach a sample of your data.
This is how I receive it. The leading zero has to remain but the hyphens must be removed. Thank You

BRANDITEM#ITEM DESCRIPTIONCOMMENTBEGINENDEACH SIZERETAIL UPCPPTRPPTRCHGPPTR
B L53030BL 30 CAN1/29/20243/3/202412 OZ0-18200-53030-2$ 19.75$ 19.75$ -$ 19.75
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
The code returned is 45 which reflects a hyphen if I'm not mistaken correct?
Thanks for the confirmation.


This is how I receive it.
Slight issue is that we cannot see from that table what the columns are. If they start at column A as would be most common, then the column in question would be column H, not column I as stated in post 1.

Assuming that it is column I then try this code with a copy of your workbook.

VBA Code:
Sub RemoveHyphens()
  With Range("I2", Range("I" & Rows.Count).End(xlUp)) '<- Adjust column if required.
    .NumberFormat = "@"
    .Value = Evaluate("substitute(" & .Address & ",""-"","""")")
  End With
End Sub

Before:

Buns1976.xlsm
ABCDEFGHIJKLM
1BRANDITEM#ITEM DESCRIPTIONCOMMENTBEGINENDEACH SIZERETAIL UPCPPTRPPTRCHGPPTR
2B L53030BL 30 CAN1/29/20243/03/202412 OZ0-18200-53030-2$19.75$19.75$ -$19.75
Sheet3


After:

Buns1976.xlsm
ABCDEFGHIJKLM
1BRANDITEM#ITEM DESCRIPTIONCOMMENTBEGINENDEACH SIZERETAIL UPCPPTRPPTRCHGPPTR
2B L53030BL 30 CAN1/29/20243/03/202412 OZ018200530302$19.75$19.75$ -$19.75
Sheet3
 
Upvote 1
Solution
Thanks for the confirmation.



Slight issue is that we cannot see from that table what the columns are. If they start at column A as would be most common, then the column in question would be column H, not column I as stated in post 1.

Assuming that it is column I then try this code with a copy of your workbook.

VBA Code:
Sub RemoveHyphens()
  With Range("I2", Range("I" & Rows.Count).End(xlUp)) '<- Adjust column if required.
    .NumberFormat = "@"
    .Value = Evaluate("substitute(" & .Address & ",""-"","""")")
  End With
End Sub

Before:

Buns1976.xlsm
ABCDEFGHIJKLM
1BRANDITEM#ITEM DESCRIPTIONCOMMENTBEGINENDEACH SIZERETAIL UPCPPTRPPTRCHGPPTR
2B L53030BL 30 CAN1/29/20243/03/202412 OZ0-18200-53030-2$19.75$19.75$ -$19.75
Sheet3


After:

Buns1976.xlsm
ABCDEFGHIJKLM
1BRANDITEM#ITEM DESCRIPTIONCOMMENTBEGINENDEACH SIZERETAIL UPCPPTRPPTRCHGPPTR
2B L53030BL 30 CAN1/29/20243/03/202412 OZ018200530302$19.75$19.75$ -$19.75
Sheet3
Yes Sir, That does the trick. The data does start in column b. Reason unknow to me but column a is hidden by the vendor who supplies the information.

Thank You kindly!
B
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,758
Members
452,940
Latest member
rootytrip

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