Transpose data require VBA

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Hello,

I need VBA which can transpose each 4th row, 3 by 3 columns, 1st digits before "-" in the columns N:P and last digits after "-" in the columns S:U.

Example....
Cells C8, D8, E8 1st digits before "-" transpose in cells N8, N9, N10
Cells F8, G8, H8 1st digits before "-" transpose in cells O8, O9, O10
Cells I8, J8, K8 1st digits before "-" transpose in cells P8, P9, P10

Cells C8, D8, E8 last digits after "-" transpose in cells S8, S9, S10
Cells F8, G8, H8 last digits after "-" transpose in cells T8, T9, T10
Cells I8, J8, K8 last digits after "-" transpose in cells U8, U9, U10

Here is the example


Book1
ABCDEFGHIJKLMNOPQRSTU
1
2
3
4
5Col1Col2Col3Col4Col5Col6Col7Col8Col9
6
7
818 - 34 - 02 - 02 - 17 - 25 - 34 - 23 - 17 - 218241312
928 - 21 - 05 - 14 - 37 - 33 - 12 - 16 - 26 - 1473021
1034 - 36 - 14 - 37 - 35 - 02 - 13 - 13 - 18 - 1257032
1147 - 53 - 24 - 05 - 22 - 07 - 12 - 19 - 33 - 047524521
1258 - 34 - 22 - 15 - 21 - 08 - 11 - 19 - 44 - 0329203
1364 - 15 - 15 - 06 - 55 - 03 - 04 - 44 - 16 - 2473010
1479 - 23 - 12 - 03 - 25 - 36 - 22 - 06 - 26 - 279327220
1587 - 33 - 14 - 16 - 22 - 16 - 01 - 19 - 44 - 1356132
1694 - 25 - 15 - 16 - 24 - 24 - 04 - 25 - 35 - 1266022
17106 - 33 - 15 - 35 - 14 - 15 - 13 - 17 - 04 - 31065310311
18118 - 54 - 02 - 12 - 05 - 17 - 04 - 35 - 25 - 2347110
19127 - 44 - 13 - 03 - 25 - 26 - 34 - 15 - 05 - 1554313
20137 - 65 - 12 - 17 - 12 - 05 - 10 - 07 - 17 - 31377013610
21143 - 24 - 27 - 28 - 30 - 06 - 03 - 110 - 41 - 0527101
22158 - 61 - 05 - 14 - 36 - 24 - 02 - 17 - 15 - 0257113
23169 - 32 - 13 - 04 - 26 - 24 - 11 - 06 - 27 - 31694116320
24175 - 42 - 07 - 35 - 27 - 02 - 04 - 35 - 05 - 2266122
25188 - 52 - 04 - 03 - 27 - 14 - 03 - 25 - 26 - 2347013
26198 - 33 - 23 - 24 - 04 - 26 - 02 - 17 - 35 - 11984219301
27206 - 43 - 15 - 26 - 33 - 05 - 12 - 08 - 34 - 0347223
28214 - 15 - 35 - 27 - 33 - 24 - 03 - 06 - 35 - 0365201
29225 - 04 - 15 - 29 - 42 - 23 - 10 - 08 - 36 - 12259022040
30236 - 44 - 04 - 11 - 17 - 06 - 37 - 53 - 04 - 0428123
31247 - 35 - 12 - 03 - 15 - 26 - 34 - 14 - 26 - 1536211
32255 - 13 - 16 - 15 - 46 - 23 - 14 - 35 - 05 - 12555425143
33264 - 37 - 33 - 06 - 32 - 06 - 24 - 25 - 05 - 1365120
34274 - 18 - 22 - 05 - 33 - 16 - 05 - 53 - 16 - 1635111
35289 - 34 - 11 - 13 - 17 - 54 - 22 - 03 - 19 - 02893228310
36297 - 53 - 04 - 26 - 24 - 14 - 11 - 07 - 26 - 1473151
37306 - 47 - 11 - 07 - 15 - 12 - 01 - 12 - 011 - 6149120
38316 - 26 - 02 - 05 - 35 - 14 - 23 - 13 - 08 - 53165331231
39325 - 36 - 03 - 26 - 15 - 03 - 13 - 23 - 08 - 5653010
40339 - 45 - 10 - 04 - 15 - 25 - 11 - 04 - 29 - 3248025
41348 - 45 - 11 - 15 - 23 - 16 - 01 - 06 - 27 - 33485134420
42357 - 14 - 03 - 15 - 35 - 14 - 42 - 05 - 17 - 3536112
433611 - 41 - 02 - 12 - 18 - 34 - 11 - 05 - 28 - 2167103
44379 - 43 - 22 - 01 - 03 - 110 - 44 - 08 - 32 - 03791437400
45385 - 22 - 17 - 15 - 46 - 23 - 04 - 26 - 14 - 1338213
46399 - 43 - 02 - 12 - 26 - 16 - 03 - 25 - 26 - 22102040
474010 - 52 - 12 - 12 - 06 - 26 - 22 - 16 - 06 - 240102240501
48266120
49266122
50
51
52
53
54
Sheet1


Thank you all
Excel 2000
Regards,
Moti
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hope this helps.

Code:
Sub test()
Dim rng As Range
Dim c, x(), z()
Dim i As Long, j As Long, k As Long, m As Long
For k = 8 To cells(Rows.count, 3).End(xlUp).Row Step 3
    m = 14
    For i = 3 To 11 Step 3
        Set rng = Range(cells(k, i), cells(k, i + 2))
        For Each c In rng
             ReDim Preserve x(j)
             x(j) = Left(c.Value, 1)
             ReDim Preserve z(j)
             z(j) = Right(c.Value, 1)
             j = j + 1
        Next
            Range(cells(k, m), cells(k + 2, m)) = WorksheetFunction.Transpose(x)
            Range(cells(k, m + 5), cells(k + 2, m + 5)) = WorksheetFunction.Transpose(z)
            j = 0
            m = m + 1
    Next
Next
End Sub
 
Upvote 0
Hope this helps.

Code:
Sub test()
Dim rng As Range
Dim c, x(), z()
Dim i As Long, j As Long, k As Long, m As Long
For k = 8 To cells(Rows.count, 3).End(xlUp).Row Step 3
    m = 14
    For i = 3 To 11 Step 3
        Set rng = Range(cells(k, i), cells(k, i + 2))
        For Each c In rng
             ReDim Preserve x(j)
             x(j) = Left(c.Value, 1)
             ReDim Preserve z(j)
             z(j) = Right(c.Value, 1)
             j = j + 1
        Next
            Range(cells(k, m), cells(k + 2, m)) = WorksheetFunction.Transpose(x)
            Range(cells(k, m + 5), cells(k + 2, m + 5)) = WorksheetFunction.Transpose(z)
            j = 0
            m = m + 1
    Next
Next
End Sub
Thank you Takae , for giving a VBA solution, it's perfect!!

Only it was transposing, H44 and C47, value instead 10 as 1
Just modified as shown below and it is fine.

Code:
For Each c In rng
             ReDim Preserve x(j)
             x(j) = Left(c.Value,[B][COLOR=#ff0000]2[/COLOR][/B])
             ReDim Preserve z(j)
             z(j) = Right(c.Value,[COLOR=#ff0000][B] 2[/B][/COLOR])
             j = j + 1
        Next

Thank you for your help

Have a nice day

Kind Regards,
Moti :)
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,980
Members
452,540
Latest member
haasro02

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