Newbie Question: Using Excel to work with output of PI - break sets of numbers, remove numbers!

robbertly

New Member
Joined
Oct 19, 2014
Messages
32
Hi,

I'm a newbie here, and to excel at this level, and have a question I hope somebody can help with.

I have a list of numbers outputted from a review of PI (the number 3.1415926535897932384......)

It looks like this:

8850838032 0621312483 8327044318 1257233570 9958940293 1391776730 2923888859 5836058683 5192760238 4694561699 : 110000000001
9312900154 4838526183 9375914106 9846458403 5847003707 2451543553 9394699328 5157228504 5434270590 6509736487 : 110000000002
1284090545 3175919151 4159855781 3410862263 2549812643 7600394225 7109902021 0694219181 6542482795 7164656581 : 110000000003
1367977800 8915483236 6072599505 1466161901 1090687303 7608155585 3289637107 6490574006 0401938787 7258319674 : 110000000004

- the list is in notepad (.txt file)
- set of 10 digits per number
- set of 10 numbers per line (10 digits per x 10 numbers per line)
- reference number at the end ( the : 110000000001 : 110000000002 etc numbers)


Heres what I would like to do:

- to remove the reference numbers first ( the : 110000000001 : 110000000002 etc numbers)
- to break each set of 10 digits into 5 sets of 2 digit numbers, with each 2 digit number appearing on a seperate line of its own - 0621312483 to 06 21 31 24 83
- from this I want to remove all 2 digit numbers over 26, so that I am only left with numbers from 01 - 26 - from 06 21 31 24 83 to 06 21 24

Any ideas of how to do this in excel?

Any assistance, suggestions, ideas welcome.

Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
robbertly,

Welcome to the MrExcel forum.

1. What version of Excel and Windows are you using?

2. Are you using a PC or a Mac?


Be back in a little while.
 
Upvote 0
robbertly,

Sample raw data:


Excel 2007
ABC
18850838032 0621312483 8327044318 1257233570 9958940293 1391776730 2923888859 5836058683 5192760238 4694561699 : 110000000001
29312900154 4838526183 9375914106 9846458403 5847003707 2451543553 9394699328 5157228504 5434270590 6509736487 : 110000000002
31284090545 3175919151 4159855781 3410862263 2549812643 7600394225 7109902021 0694219181 6542482795 7164656581 : 110000000003
41367977800 8915483236 6072599505 1466161901 1090687303 7608155585 3289637107 6490574006 0401938787 7258319674 : 110000000004
5
Sheet1


After the macro (using two arrays in memory) in column C:


Excel 2007
C
106
221
324
404
518
612
723
802
913
1023
1105
1202
1316
1412
1501
1606
1703
1800
1907
2024
2122
2204
2305
2409
2512
2609
2705
2810
2922
3025
3126
3200
3325
3409
3520
3621
3706
3821
3913
4000
4115
4205
4314
4416
4519
4601
4710
4803
4908
5015
5107
5206
5304
5401
55
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub BreakSets()
' hiker95, 10/19/2014, ME812677
Dim a As Variant, o As Variant
Dim i As Long, j As Long
Dim s, k As Long, n As Long
Dim lr As Long
Application.ScreenUpdating = False
lr = Cells(Rows.Count, 1).End(xlUp).Row
a = Range("A1:A" & lr).Value
ReDim o(1 To lr * 50, 1 To 1)
For i = 1 To lr
  s = Split(Left(a(i, 1), 109), " ")
  For k = LBound(s) To UBound(s)
    For n = 1 To 10 Step 2
      If Mid(s(k), n, 2) < 27 Then
        j = j + 1
        o(j, 1) = Mid(s(k), n, 2)
      End If
    Next n
  Next k
Next i
Columns(3).ClearContents
With Range("C1").Resize(j)
  .NumberFormat = "@"
  .Value = o
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the BreakSets macro.
 
Upvote 0
robbertly,

With the same sample raw data in my reply #3:

After this next macro:


Excel 2007
C
100
201
302
403
504
605
706
807
908
1009
1110
1212
1313
1414
1515
1616
1718
1819
1920
2021
2122
2223
2324
2425
2526
26
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Sub BreakSets_V2()
' hiker95, 10/19/2014, ME812677
Dim rng As Range, c As Range, o
Dim s, i As Long, n As Long
Application.ScreenUpdating = False
Set rng = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
With CreateObject("Scripting.Dictionary")
  For Each c In rng
    s = Split(Left(c, 109), " ")
    For i = LBound(s) To UBound(s)
      For n = 1 To 10 Step 2
        If Mid(s(i), n, 2) < 27 Then
          If Not .Exists(Mid(s(i), n, 2)) Then
            .Add Mid(s(i), n, 2), Mid(s(i), n, 2)
          End If
        End If
      Next n
    Next i
  Next c
  o = Application.Transpose(Array(.Keys))
  n = .Count
End With
Columns(3).ClearContents
With Range("C1").Resize(n)
  .NumberFormat = "@"
  .Value = o
  .Sort key1:=Range("C1"), order1:=1
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the BreakSets_V2 macro.
 
Upvote 0
robbertly,

With the same sample raw data in my reply #3:

And, after the last macro:


Excel 2007
CD
1003
2013
3022
4032
5043
6054
7064
8072
9081
10093
11102
12123
13132
14141
15152
16162
17181
18191
19201
20213
21222
22232
23242
24252
25261
26
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Sub BreakSets_V3()
' hiker95, 10/19/2014, ME812677
Dim rng As Range, c As Range, o
Dim s, i As Long, n As Long
Application.ScreenUpdating = False
Set rng = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
With CreateObject("Scripting.Dictionary")
  For Each c In rng
    s = Split(Left(c, 109), " ")
    For i = LBound(s) To UBound(s)
      For n = 1 To 10 Step 2
        If Mid(s(i), n, 2) < 27 Then
          If Not .Exists(Mid(s(i), n, 2)) Then
            .Add Mid(s(i), n, 2), 1
          Else
            .Item(Mid(s(i), n, 2)) = .Item(Mid(s(i), n, 2)) + 1
          End If
        End If
      Next n
    Next i
  Next c
  Range("C1").Resize(.Count).NumberFormat = "@"
  Range("C1").Resize(.Count).Value = Application.Transpose(.Keys)
  Range("D1").Resize(.Count).Value = Application.Transpose(.Items)
  Range("C1:D" & .Count).Sort key1:=Range("C1"), order1:=1
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the BreakSets_V3 macro.
 
Upvote 0
Hi Hiker95,

thanks for getting back to me on this so quickly...

Absolutely brilliant, really impressed... your first code/macro worked perfectly.... really appreciate the effort and work on that.

Just one more question if you don't mind...

The output from the four lines of numbers was 54 numbers under 26, in a descending line of 54 numbers. I will be using a couple of thousand numbers and wonder if itwould it be possible to alter the macro to create a new column after it reaches a count of 250 numbers under 26 i.e. column C = 1-250, D = 251-500, E = 501 to 750 etc.

If thats possible.... thats my problem solved!

Many thanks,

R
 
Upvote 0
robbertly,

Thanks for the feedback.

You are very welcome. Glad I could help.


The output from the four lines of numbers was 54 numbers under 26, in a descending line of 54 numbers. I will be using a couple of thousand numbers and wonder if it would it be possible to alter the macro to create a new column after it reaches a count of 250 numbers under 26 i.e. column C = 1-250, D = 251-500, E = 501 to 750 etc.

If thats possible.... thats my problem solved!

Yes it is. Let me think about this.
 
Upvote 0
robbertly,

I duplicated your four row groups down to row 120 (not all rows are shown for brevity):


Excel 2007
A
18850838032 0621312483 8327044318 1257233570 9958940293 1391776730 2923888859 5836058683 5192760238 4694561699 : 110000000001
29312900154 4838526183 9375914106 9846458403 5847003707 2451543553 9394699328 5157228504 5434270590 6509736487 : 110000000002
31284090545 3175919151 4159855781 3410862263 2549812643 7600394225 7109902021 0694219181 6542482795 7164656581 : 110000000003
41367977800 8915483236 6072599505 1466161901 1090687303 7608155585 3289637107 6490574006 0401938787 7258319674 : 110000000004
58850838032 0621312483 8327044318 1257233570 9958940293 1391776730 2923888859 5836058683 5192760238 4694561699 : 110000000001
69312900154 4838526183 9375914106 9846458403 5847003707 2451543553 9394699328 5157228504 5434270590 6509736487 : 110000000002
71284090545 3175919151 4159855781 3410862263 2549812643 7600394225 7109902021 0694219181 6542482795 7164656581 : 110000000003
81367977800 8915483236 6072599505 1466161901 1090687303 7608155585 3289637107 6490574006 0401938787 7258319674 : 110000000004
1178850838032 0621312483 8327044318 1257233570 9958940293 1391776730 2923888859 5836058683 5192760238 4694561699 : 110000000001
1189312900154 4838526183 9375914106 9846458403 5847003707 2451543553 9394699328 5157228504 5434270590 6509736487 : 110000000002
1191284090545 3175919151 4159855781 3410862263 2549812643 7600394225 7109902021 0694219181 6542482795 7164656581 : 110000000003
1201367977800 8915483236 6072599505 1466161901 1090687303 7608155585 3289637107 6490574006 0401938787 7258319674 : 110000000004
121
Sheet1


And, ran the new macro (using two arrays in memory), and, got this (not all rows are shown for brevity):


Excel 2007
BCDEFGHIJ
106200108221314
221210615252316
324060307260519
404210006000201
518130704251610
612002401091203
723152206200108
802050421210615
11713140524060307
11823160904210006
11905191218130704
12002010912002401
121161005231522
122120310020504
123010822131405
124061525231609
247260519121813
248000201091200
249251610052315
250091203100205
251
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Code:
Sub BreakSetsInto250Rows()
' hiker95, 10/20/2014, ME812677
Dim a As Variant, o(1 To 250, 1 To 1) As Variant
Dim i As Long, j As Long
Dim s, k As Long, n As Long
Dim lr As Long, lc As Long, nc As Long
Application.ScreenUpdating = False
lc = Cells(1, Columns.Count).End(xlToLeft).Column
If lc > 1 Then Columns(3).Resize(, lc - 2).ClearContents
lr = Cells(Rows.Count, 1).End(xlUp).Row
a = Range("A1:A" & lr).Value
nc = 2
For i = 1 To lr
  s = Split(Left(a(i, 1), 109), " ")
  For k = LBound(s) To UBound(s)
    For n = 1 To 10 Step 2
      If Mid(s(k), n, 2) < 27 Then
        j = j + 1
        o(j, 1) = Mid(s(k), n, 2)
        If j = 250 Then
          nc = nc + 1
          Columns(nc).ClearContents
          With Cells(1, nc).Resize(j)
            .NumberFormat = "@"
            .Value = o
          End With
          Erase o
          j = 0
        End If
      End If
    Next n
  Next k
Next i
If j > 0 Then
  nc = nc + 1
  Columns(nc).ClearContents
  With Cells(1, nc).Resize(j)
    .NumberFormat = "@"
    .Value = o
  End With
End If
Columns(3).Resize(, nc - 2).AutoFit
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the BreakSetsInto250Rows macro.
 
Upvote 0

Forum statistics

Threads
1,215,131
Messages
6,123,223
Members
449,091
Latest member
jeremy_bp001

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