admiral100
Well-known Member
- Joined
- Jan 17, 2015
- Messages
- 873
Hi ,
This code works fine. (Split Column A & B to 3 columns)
Sub SplitInto3CellsPerColumn()
Dim X As Long, LastRow As Long, vArrIn As Variant, vArrIn2 As Variant, vArrOut As Variant, vArrOut2 As Variant
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
vArrIn = Range("A1:A" & LastRow)
vArrIn2 = Range("B1:B" & LastRow)
ReDim vArrOut(1 To 3, 1 To Int(LastRow / 3) + 1)
ReDim vArrOut2(1 To 3, 1 To Int(LastRow / 3) + 1)
For X = 0 To LastRow - 1
vArrOut(1 + (X Mod 3), 1 + Int(X / 3)) = vArrIn(X + 1, 1)
vArrOut2(1 + (X Mod 3), 1 + Int(X / 3)) = vArrIn2(X + 1, 1)
Next
Range("M1").Resize(3, UBound(vArrOut, 2)) = vArrOut
Range("M6").Resize(3, UBound(vArrOut2, 2)) = vArrOut2
End Sub
The output:
10 40 70
20 50 80
30 60 90
A D G
B E H
C F I
How should I change the code so that the output will be like this: (Odd & Even columns)
10 A 40 D 70 G
20 B 50 E 80 H
30 C 60 F 90 I
Thanks
This code works fine. (Split Column A & B to 3 columns)
Sub SplitInto3CellsPerColumn()
Dim X As Long, LastRow As Long, vArrIn As Variant, vArrIn2 As Variant, vArrOut As Variant, vArrOut2 As Variant
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
vArrIn = Range("A1:A" & LastRow)
vArrIn2 = Range("B1:B" & LastRow)
ReDim vArrOut(1 To 3, 1 To Int(LastRow / 3) + 1)
ReDim vArrOut2(1 To 3, 1 To Int(LastRow / 3) + 1)
For X = 0 To LastRow - 1
vArrOut(1 + (X Mod 3), 1 + Int(X / 3)) = vArrIn(X + 1, 1)
vArrOut2(1 + (X Mod 3), 1 + Int(X / 3)) = vArrIn2(X + 1, 1)
Next
Range("M1").Resize(3, UBound(vArrOut, 2)) = vArrOut
Range("M6").Resize(3, UBound(vArrOut2, 2)) = vArrOut2
End Sub
The output:
10 40 70
20 50 80
30 60 90
A D G
B E H
C F I
How should I change the code so that the output will be like this: (Odd & Even columns)
10 A 40 D 70 G
20 B 50 E 80 H
30 C 60 F 90 I
Thanks