Split Series

ayazgreat

Well-known Member
Joined
Jan 19, 2008
Messages
1,151
Hi

I want to split a column series as per its left three 3 digits into different columns as example given below.

Excel Workbook
ABCDE
1Series210214810803
22100021000214008100080300
32100121001214018100080301
42100221002214028100080302
52100321003214038100080303
621004210042140481000
721005210052140581000
82140081000
921401
1021402
1121403
1221404
1321405
1481000
1581000
1681000
1781000
1881000
1981000
2081000
2180300
2280301
2380302
2480303
Sheet1


Could any body please help me ?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Macro with Advanced Filter

Hello,

my code provides that Columns("G:N") are unused/empty:

<div style="background-color:#FFFFFF; border-width:2px; border-style: groove; border-color:#ff9966; padding:4px;"><nobr><span style="font-family:Courier New,Arial; font-size:9pt ;" ><b><span style="color:#000080"; >Sub</span> Advanced_Filter()</b><br />    Columns(<span style="color:#800000"; >"B:E"</span>).Clear<br />    Range(<span style="color:#800000"; >"G1:N1"</span>).FormulaR1C1 = <span style="color:#800000"; >"Series"</span><br />    Range(<span style="color:#800000"; >"G2"</span>).FormulaR1C1 = <span style="color:#800000"; >">=21000"</span><br />    Range(<span style="color:#800000"; >"H2"</span>).FormulaR1C1 = <span style="color:#800000"; >"<21100"</span><br />    Range(<span style="color:#800000"; >"I2"</span>).FormulaR1C1 = <span style="color:#800000"; >">=21400"</span><br />    Range(<span style="color:#800000"; >"J2"</span>).FormulaR1C1 = <span style="color:#800000"; >"<21500"</span><br />    Range(<span style="color:#800000"; >"K2"</span>).FormulaR1C1 = <span style="color:#800000"; >">=81000"</span><br />    Range(<span style="color:#800000"; >"L2"</span>).FormulaR1C1 = <span style="color:#800000"; >"<81100"</span><br />    Range(<span style="color:#800000"; >"M2"</span>).FormulaR1C1 = <span style="color:#800000"; >">=80300"</span><br />    Range(<span style="color:#800000"; >"N2"</span>).FormulaR1C1 = <span style="color:#800000"; >"<80400"</span><br />    <br />    Range(<span style="color:#800000"; >"A:A"</span>).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _<br />        <span style="color:#800000"; >"G1:H2"</span>), CopyToRange:=Range(<span style="color:#800000"; >"B1"</span>), Unique:=False<br />    Range(<span style="color:#800000"; >"A:A"</span>).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _<br />        <span style="color:#800000"; >"I1:J2"</span>), CopyToRange:=Range(<span style="color:#800000"; >"C1"</span>), Unique:=False<br />    Range(<span style="color:#800000"; >"A:A"</span>).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _<br />        <span style="color:#800000"; >"K1:L2"</span>), CopyToRange:=Range(<span style="color:#800000"; >"D1"</span>), Unique:=False<br />    Range(<span style="color:#800000"; >"A:A"</span>).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _<br />        <span style="color:#800000"; >"M1:N2"</span>), CopyToRange:=Range(<span style="color:#800000"; >"E1"</span>), Unique:=False<br />    <br />    Range(<span style="color:#800000"; >"B1"</span>).FormulaR1C1 = <span style="color:#800000"; >"210"</span><br />    Range(<span style="color:#800000"; >"C1"</span>).FormulaR1C1 = <span style="color:#800000"; >"214"</span><br />    Range(<span style="color:#800000"; >"D1"</span>).FormulaR1C1 = <span style="color:#800000"; >"810"</span><br />    Range(<span style="color:#800000"; >"E1"</span>).FormulaR1C1 = <span style="color:#800000"; >"803"</span><br />    Columns(<span style="color:#800000"; >"G:N"</span>).Clear<br /><b><span style="color:#000080"; >End</span> <span style="color:#000080"; >Sub</span></b><br /></span></nobr></div><br/><div style=" background-color:#f8f8f8; border-width:2px; border-style: groove; border-color:#ff9966; padding:4px; width:300px;" >Codehighlighting with <a href="http://www.haserodt.de/cj_pro/cjdirect.php" >CodeJeanieDirectHtml</a></div>
 
Upvote 0
Re: Macro with Advanced Filter

try
Code:
Sub test()
Dim a, e, w(), z As String, x, y, i As Long
With Range("a1").CurrengRegion.Resize(, 1)
    a = .Value
    With CreateObject("Scripting.Dictionary")
        For Each e In a
            z = Left(e, 3)
            If Not .exists(e) Then
                ReDim w(1 To 1) : w(1) = e
                .add z, w
            Else
                w = .item(z) : ReDim Preserve w(1 To UBound(w) + 1)
                w(UBound(w)) = e : .item(z) = w
            End If
        Next
        x = .keys : y = .items
    End With
    With .Offset(, .Columns.Count)
        .Resize(, UBound(x) + 1).ClearContents
        For i = 0 To UBound(x)
            .Offset(, i).Value = x(i)
            .Offset(1, i).Resize(UBound(y(i), 2), UBound(y(i), 1)).Value = _
            Application.Transpose(y(i))
        Next
    End With
End With
End Sub
 
Upvote 0
Thanks Seiya

But there is an error messege in your code in this line "Object does not support this property or methoed"

With Range("a2").CurrengRegion.Resize(, 1)
 
Upvote 0
Now error at this line

"This key is already associated with an element of this collection"

.Add z, w
 
Upvote 0
Hummm typo...
Rich (BB code):
Sub test()
Dim a, e, w(), z As String, x, y, i As Long
With Range("a2").CurrentRegion.Resize(, 1)
    a = .Value
    With CreateObject("Scripting.Dictionary")
        For Each e In a
            z = Left(e, 3)
            If Not .exists(z) Then
                ReDim w(1 To 1) : w(1) = e
                .add z, w
            Else
                w = .item(z) : ReDim Preserve w(1 To UBound(w) + 1)
                w(UBound(w)) = e : .item(z) = w
            End If
        Next
        x = .keys : y = .items
    End With
    With .Offset(, .Columns.Count)
        .Resize(, UBound(x) + 1).ClearContents
        With .Resize(1, 1)
            For i = 0 To UBound(x)
                .Offset(, i).Value = x(i)
                .Offset(1, i).Resize(UBound(y(i))).Value = _
                Application.Transpose(y(i))
            Next
        End With
    End With
End With
End Sub
 
Upvote 0
Thank you very much Seiya it works great

But it is also spliting text in colunm a1 as mentioned below in column b

Excel Workbook
ABCDEFG
1SeriesSer210214810803
221000Series21000214008100080300
32100121001214018100080301
42100221002214028100080302
52100321003214038100080303
621004210042140481000
721005210052140581000
82140081000
921401
1021402
1121403
1221404
1321405
1481000
1581000
1681000
1781000
1881000
1981000
2081000
2180300
2280301
2380302
2480303
Sheet1
 
Upvote 0
change
Rich (BB code):
With Range("a2").CurrentRegion.Resize(, 1)
    a = .Value
to
Rich (BB code):
With Range("a2").CurrentRegion.Resize(, 1)
    a = .Resize(.Rows.Count - 1).Offset(1).Value
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,729
Members
449,049
Latest member
MiguekHeka

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