I am trying to take a column of data that I want to paste in five different columns. I want it to go:
1 to 12345
2 12345
3 12345
4 12345
5 12345
1
2
3
4
5
... and so on. Here is the code:
Here is the line the error occurs:
I'm not sure how to adjust it.
1 to 12345
2 12345
3 12345
4 12345
5 12345
1
2
3
4
5
... and so on. Here is the code:
Code:
Option Explicit
Sub ReArrangeCells()
Dim ws As Worksheet, LastRow As Long
Set ws = Excel.ActiveSheet
LastRow = Range("G71311").End(xlUp).Row
Dim i As Long, j As Long, FromCell As Range, ToCell As Range, sNewCol As String, sNewRow As String
For i = 1 To LastRow
Set FromCell = ws.Range("G" & i) 'the cell we want to move
sNewCol = IIf(i Mod 5 = 0, Chr$(79), Chr$((i Mod 5) + 25))
sNewRow = IIf(i Mod 5 = 0, (i \ 5), (i \ 5) + 1)
Set ToCell = ws.Range(sNewCol & sNewRow) 'the cell we want to copy the data to
FromCell.Copy ToCell
If i <> 1 Then FromCell.Clear
If i Mod 100 = 0 Then DoEvents
Next i
End Sub
Here is the line the error occurs:
Code:
Set ToCell = ws.Range(sNewCol & sNewRow) 'the cell we want to copy the data to
I'm not sure how to adjust it.
Last edited: