Solved

grouping digits in differents columns

Posted on 2007-03-26
12
294 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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 on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

911 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

22 Experts available now in Live!

Get 1:1 Help Now