Hello,
I am trying to write a code that will loop through a set of data and copy certain cells in each row. It is to paste the certain cells into another spreadsheet in the same workbook.
Ex. If I run a query and it pulls back 20 rows of data into sheet1 the code should cycle through all 20 rows, copy columns C-G (excluding E), and paste them in sheet4.
Here is my code so far (I get an overflow error):
Sub Loop6()
' This loop repeats for a fixed number of times determined by the number of rows
' in the range
Dim j As Integer
For j = 1 To Selection.CurrentRegion.Rows.Count - 1
ActiveCell.FormulaR1C1 = "=Average(RC[-1],RC[-2])"
ActiveCell.Offset(1, 0).Select
Rows(j).Copy Rows(j + 1)
Sheet4.Select
Next j
End Sub
I am trying to write a code that will loop through a set of data and copy certain cells in each row. It is to paste the certain cells into another spreadsheet in the same workbook.
Ex. If I run a query and it pulls back 20 rows of data into sheet1 the code should cycle through all 20 rows, copy columns C-G (excluding E), and paste them in sheet4.
Here is my code so far (I get an overflow error):
Sub Loop6()
' This loop repeats for a fixed number of times determined by the number of rows
' in the range
Dim j As Integer
For j = 1 To Selection.CurrentRegion.Rows.Count - 1
ActiveCell.FormulaR1C1 = "=Average(RC[-1],RC[-2])"
ActiveCell.Offset(1, 0).Select
Rows(j).Copy Rows(j + 1)
Sheet4.Select
Next j
End Sub