Macro to seperate an alphanumeric line

shajueasow

Well-known Member
Joined
Oct 7, 2004
Messages
1,926
Hi all,
When a file (not an Excel file) is opened in Excel, I come across an alphanumeric line like this. HH091002345020205 or HQ091002345020205. This line is in cell A1. I want it divided like this HH-091-002345-020205, where it is seperated into 4 columns as shown. HH is a ID tag, 091 a loc code, 002345 is a running number, and the rest is the date of action. How can a macro be written to do this (the macro should divide those line starting HH and delete lines starting with HQ) so that it will check till the last entry in Column A.
TIA
 

Some videos you may like

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

tactps

Well-known Member
Joined
Jan 20, 2004
Messages
3,459
You don't really need a macro for this, but if required, you could record one while following these steps:

The easy way is to:
Insert 3 columns
From the Data Menu, Choose "Text to columns"
Then choose fixed width.
Click where you want the separations.

Then sort and delete all "HQ" lines.
 

RalphA

Well-known Member
Joined
May 14, 2003
Messages
3,829
shajueasow said:
Hi all,
When a file (not an Excel file) is opened in Excel, I come across an alphanumeric line like this. HH091002345020205 or HQ091002345020205. This line is in cell A1. I want it divided like this HH-091-002345-020205, where it is seperated into 4 columns as shown. HH is a ID tag, 091 a loc code, 002345 is a running number, and the rest is the date of action. How can a macro be written to do this (the macro should divide those line starting HH and delete lines starting with HQ) so that it will check till the last entry in Column A.
TIA
As long as the alphanumeric line has the same number of characters, and you ALWAYS need the first 2, the next 3, the next 6, the last 6, you can use formulas.

Say the alphanumeric line is in A2. Then:
In B2, enter =MID(A2,1,2), and copy down
In C2, enter =MID(A2,3,3), and copy down
In D2, enter =MID(A2,6,6), and copy down
In E2, enter =MID(A2,12,6), and copy down

That should do it!
 

shajueasow

Well-known Member
Joined
Oct 7, 2004
Messages
1,926
Hello tactps and RalphA,
Thanks a lot for your help in this regard. This was a thing which was nagging me for quiet sometime. And it had came to a happy ending.
Once again thanks a lot.. (y)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,421
Messages
5,596,033
Members
414,039
Latest member
southike

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
Top