I have a column of data of which I would like to copy a range of four cells to a another range in a different worksheet. This should be in a loop which changes the starting cells to copy every time.
I am more or less new to macro programming and can't get beyond the following code, which already at the beginning gives me a compile error ("Sub or function not defined), I am not sure what the reason for that is... Also, I have a feeling that I am changing my variables, but not actually printing something into the cells.
Any help would be greatly appreciated!
Cheers, dahlai
Sub CopyingPeriod2()
Dim ws As Worksheet
Set ws = Worksheets("1")
Dim OneCells As Range
Set OneCells = ws.Range("C1:C4")
Dim works As Worksheet
Set works = Worksheet("New")
Dim NewCells As Range
Set NewCells = works.Range("J51:J54")
Do Until ActiveCell.Value = ""
NewCells.Value = OneCells.Value
OneCells = OneCells.Offset(8, 0)
NewCells = NewCells.Offset(0, 1)
Loop
End Sub
Update:
Answering the comments: The C1:C4 range is to be offset by 8 rows every time the loop runs. The J51 cell is to be offset by 1 column every time the loop runs.
I continued trying and came up with the following code (No loop included,yet): Copy and paste works. However, when the OneCells is updated the cells of the original range in the worksheet go blank and OneCells.Select selects the same range as before
Sub CopyingPeriod2d()
Dim OneCells As Range
Set OneCells = Range("C1:C4")
Worksheets("1").Activate
OneCells.Select
Selection.Copy
Worksheets("New").Activate
Range("J51").PasteSpecial xlPasteValues
Worksheets("1").Activate
OneCells.Select
ActiveCell.Offset(8, 0).Select
OneCells = Range(ActiveCell, ActiveCell.Offset(4, 0))
OneCells.Select