My data comes in several forms and I need to convert it to a unified form (VBA)

mick0005

Active Member
Joined
Feb 21, 2011
Messages
406
Hi all,


I have SKUs that comes from several sources. The problem with these sources is that they aren't consistent. All SKUs need to be 8 digits with no symbols in it and no spaces and no blanks at the beginning or end.


I have several formulas I have been using to convert this data manually every time I import it with some helper columns, but this is a huge time suck.


I'd like to be able to just select the range of data I need converted and then it would convert in place. Here are the issues I have and would need converted:


Excel 2010
EFG
8ProblemInputOutput
9hyphen in the middle12345-67812345678
10only 6 numbers; needs 2 zeroes added at the beginning12345600123456
11only 7 numbers; needs 1 zero added at the beginning012345600123456
12requires no change1234567812345678

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Removing "-"
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Formula in G9 would be: =IFERROR(LEFT(F9,SEARCH("-",F9,1)-1)&RIGHT(F9,LEN(F9)-SEARCH("-",F9,1)),F9) and drag till end.

Set cell formatting for column G to "Custom" and put 8 zeros in Type [ Format Cells -> Custom -> Type -> 00000000]

Hope this solves your problem.

Regards
Tushar
 
Upvote 0
Formula in G9 would be: =IFERROR(LEFT(F9,SEARCH("-",F9,1)-1)&RIGHT(F9,LEN(F9)-SEARCH("-",F9,1)),F9) and drag till end.

Set cell formatting for column G to "Custom" and put 8 zeros in Type [ Format Cells -> Custom -> Type -> 00000000]

Hope this solves your problem.

Regards
Tushar

Hi Tushar,

Thank you for your suggestion. In fact, this is more or less the formula that I am using at the moment to accomplish this. I am wondering whether there is some VBA that can do this for me. I am trying to shave off some precious minutes or even seconds from this process because it is something that has to be done very frequently. Automating this will save lots of time in the long haul.

I think I could probably record a macro that would do this for me by adding a helper column, putting in the formula, and then copying and pasting this over the original column as values and deleting the helper column, but I am wondering if there is code that could do it all in place.

Thanks to anyone that can help.
 
Upvote 0

Forum statistics

Threads
1,203,313
Messages
6,054,696
Members
444,741
Latest member
MCB024

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