Solved

grouping digits in differents columns

Posted on 2007-03-26
12
293 Views
Last Modified: 2008-03-20
I have a file codebars.txt this file contains numbers in one row, I need put in differents rows groups of 13 digists.
Example
A1: 9788478290413978840309217497899780740399789681909284
I need cut in strings , 13 digits for columns
a1: 9788478290413
b1:9788403092174
c1:9789978074039
d1:9789681909284

The function LEFT only obtain the first 13 digits
Thanks
0
Comment
Question by:eccd
  • 4
  • 2
  • 2
  • +3
12 Comments
 
LVL 75
ID: 18797967
You could use the Split() function ... let me dig up an example.

mx
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 18797994
Use MID function:

=MID(A1,1,13)
=MID(A1,14,13)
=MID(A1,27,13)
=MID(A1,40,13)

Kevin
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 18798001
Import that data into column A and then run this macro with the worksheet active:

Public Sub SplitData()

   Dim Cell As Range
   
   For Each Cell In Intersect(UsedRange, [A:A]).Cells
      Cell.Offset(0, 1).Resize(1, 4).NumberFormat = "@"
      Cell.Offset(0, 1) = Mid(Cell, 1, 13)
      Cell.Offset(0, 2) = Mid(Cell, 14, 13)
      Cell.Offset(0, 3) = Mid(Cell, 27, 13)
      Cell.Offset(0, 4) = Mid(Cell, 40, 13)
   Next Cell
   [A:A].Delete

End Sub

Kevin
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 18799393
which database system are you using?

you would normally use the SUBSTRING function (or SUBSTR in some dialects)

select
 substring(yourcolumn,1,13) as part1,
 substring(yourcolumn,14,13) as part2,
 substring(yourcolumn,27,13) as part3,
 substring(yourcolumn,40,13) as part4


0
 

Author Comment

by:eccd
ID: 18803026
Zorvek.
runtime error 424 object required

Lowfatspread: this is a file in MSexcel
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 18803047
Public Sub SplitData()

   Dim Cell As Range
   
   For Each Cell In Intersect(ActiveSheet.UsedRange, ActiveSheet.[A:A]).Cells
      Cell.Offset(0, 1).Resize(1, 4).NumberFormat = "@"
      Cell.Offset(0, 1) = Mid(Cell, 1, 13)
      Cell.Offset(0, 2) = Mid(Cell, 14, 13)
      Cell.Offset(0, 3) = Mid(Cell, 27, 13)
      Cell.Offset(0, 4) = Mid(Cell, 40, 13)
   Next Cell
   ActiveSheet.[A:A].Delete

End Sub

Kevin
0
 
LVL 75
ID: 18803063
I'm still working on that Join example, lol. No ... just kidding ... you guys are on it :-)

mx
0
 

Author Comment

by:eccd
ID: 18803942
Thanks Zorvek

the perfect solution is
=mid(A$1,b1...bn,13)  
but the problem is that the copdebars.txt is very very long, and the excel have problems with it.
Maybe some scrit in vbs or php?
0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 125 total points
ID: 18804014
That's what this does:

Public Sub SplitData()

   Dim Cell As Range
   
   For Each Cell In Intersect(ActiveSheet.UsedRange, ActiveSheet.[A:A]).Cells
      Cell.Offset(0, 1).Resize(1, 4).NumberFormat = "@"
      Cell.Offset(0, 1) = Mid(Cell, 1, 13)
      Cell.Offset(0, 2) = Mid(Cell, 14, 13)
      Cell.Offset(0, 3) = Mid(Cell, 27, 13)
      Cell.Offset(0, 4) = Mid(Cell, 40, 13)
   Next Cell
   ActiveSheet.[A:A].Delete

End Sub

Kevin
0
 
LVL 7

Assisted Solution

by:SamIDRC
SamIDRC earned 125 total points
ID: 19712043
Hi eccd,

If your data from "codebars.txt" is imported into the spreadsheet in column A, then the following formula could split this into 13-character chunks.

B1: =MID($A1,(COLUMN()-2)*13+1,13)
(copy/paste across C1,D1, etc, and down the rows)

Another approach is to use the Data | Get External Data | Import Text File menu, and manually select the 13-character boundaries and "text" for each column.  Save to a "new sheet" and save the file.  This should save the "Query" so the next time "codebars.txt" changes, a simple right-click "Refresh Data" will reimport it into the same places.

  Good luck,

/Sam M.
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21177272
Forced accept.

Computer101
EE Admin
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now