Hi everyone!
I´m new to the forum and VBA/macro-programming aswell.
I need help solving a quite easy(I think) problem.
The background
I've an excel with a couple of thousand information that should be on the following form
Account# data1 data2 data3
Right now, the excel looks like this:
Column A
A1 Account#
A2 data1 B2 data1 C2etc etc
A3 data2 B3 data2 C3etc etc
A4 data3 B4 data3
Blank row
A1 Account#
A2 data1 B2 data1 C2etc etc
A3 data2 B3 data2 C3etc etc
A4 data3 B4 data3
Blank row
and so on
What I need to do is to move all of the data1 to column B and all of the data2 to column C and so on..
I found a similar code but it doesn't carry all the information.
Sub CopyAndReformat()
Dim LastRow As Long, R As Long
Dim N As Long
Dim DstWks As Worksheet
Dim SrcWks As Worksheet
Set SrcWks = Worksheets("Sheet1") 'Name of the worksheet to copy from
Set DstWks = Worksheets("Sheet2") 'Name of the worksheet to coy to
'LastRow on the Source Worksheet
LastRow = SrcWks.Cells(Rows.Count, "A").End(xlUp).Row
For R = 1 To LastRow Step 3
N = N + 1
DstWks.Cells(N, "A") = SrcWks.Cells(R, "A")
DstWks.Cells(N, "B") = SrcWks.Cells(R + 1, "A")
DstWks.Cells(N, "C") = SrcWks.Cells(R + 2, "A")
Next R
End Sub
I´m new to the forum and VBA/macro-programming aswell.
I need help solving a quite easy(I think) problem.
The background
I've an excel with a couple of thousand information that should be on the following form
Account# data1 data2 data3
Right now, the excel looks like this:
Column A
A1 Account#
A2 data1 B2 data1 C2etc etc
A3 data2 B3 data2 C3etc etc
A4 data3 B4 data3
Blank row
A1 Account#
A2 data1 B2 data1 C2etc etc
A3 data2 B3 data2 C3etc etc
A4 data3 B4 data3
Blank row
and so on
What I need to do is to move all of the data1 to column B and all of the data2 to column C and so on..
I found a similar code but it doesn't carry all the information.
Sub CopyAndReformat()
Dim LastRow As Long, R As Long
Dim N As Long
Dim DstWks As Worksheet
Dim SrcWks As Worksheet
Set SrcWks = Worksheets("Sheet1") 'Name of the worksheet to copy from
Set DstWks = Worksheets("Sheet2") 'Name of the worksheet to coy to
'LastRow on the Source Worksheet
LastRow = SrcWks.Cells(Rows.Count, "A").End(xlUp).Row
For R = 1 To LastRow Step 3
N = N + 1
DstWks.Cells(N, "A") = SrcWks.Cells(R, "A")
DstWks.Cells(N, "B") = SrcWks.Cells(R + 1, "A")
DstWks.Cells(N, "C") = SrcWks.Cells(R + 2, "A")
Next R
End Sub