Really new to VBA, so forgive any stoopid things I say/do. This site has been a huge help in my accelerated learning so far.
I have a set of data in Excel that I need to rearrange using VBA. I want to take (cut) data from columns AF:AR for a row and move (paste) it to columns J:V in a new row inserted below the original one. The data set is a different size each time I run the report, so I am approaching it from the end of the data set and moving up through the spreadsheet. The data set has headers, so it stops at row 2. My plan so far is to move to the end of the data set, cut the data from the last row and paste it on the row below, insert a blank row above, then move up a row and repeat until row 2 is reached.
Here's what I have so far:
' Move to end of data.
Selection.End(xlDown).Select
' Repeat loop until top of data is reached..
Do Until ActiveCell.Row = 2
' Get row address of active cell.
ActiveRow = ActiveCell.Row
' Cut and paste data to row below current row.
Range(Cells(ActiveRow, "AF"), Cells(ActiveRow, "AR")).Cut Range("J" & ActiveRow).Offset(1, 0)
' Insert a blank row above.
ActiveCell.Offset(-1, 0).Select
ActiveCell.EntireRow.Insert Shift:=xlDown
' Move to next row of data up.
ActiveCell.Offset(-1, 0).Select
Loop
When running, I get this error
"Run-time error '1004': Application-defined or object-defined error."
and debug points me to the following line:
Range(Cells(ActiveRow, "AF"), Cells(ActiveRow, "AR")).Cut Range("J" & ActiveRow).Offset(1, 0)
I can't find any info on using the dynamic range with offset in the .Cut function, so this may be the problem. Is there something wrong/missing from my syntax or is there a simpler way to accomplish my goal?
Thanks in advance for sharing your genius.