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
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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.
 
Upvote 0
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!
 
Upvote 0
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)
 
Upvote 0

Forum statistics

Threads
1,213,560
Messages
6,114,309
Members
448,564
Latest member
ED38

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