I am trying to automate one report in Excel. I started with creating macro. At one point in macro I am copying one row from AZ2 to CJ2 using variables, each cell has formulas and I want to paste the same formulas from AZ3 to AZ248000. I am getting error for this code Wb1.Sheets("Gains Data").Range(Cells(row3, Col1), Cells(Row2, Col1)).Select
I already tried number of examples and solutions provided online, I started with autofill, also tried to just pasting formula. I tried to activate file, sheet, worksheet as suggested for the similar problems online. Nothing worked. Please check my code and advise the solution. PS - before this code there is bunch of code where I am copying data from different workbook Wb2 onto the main one Wb1.
Dim Row1 As Long
Dim Row2 As Long
Dim row3 As Long
Dim Col1 As String
Dim Col2 As String
Wb1.Worksheets("Gains Data").Range("AY2").Select
Selection.End(xlDown).Select
Row2 = ActiveCell.Row
' Wb1.Worksheets("Gains Data").Range("AZ2").Select
' Selection.End(xlToRight).Select
' Col2 = ActiveCell.Column
Wb1.Worksheets("Gains Data").Range("AZ2").Select
Row1 = ActiveCell.Row
row3 = Row1 + 1
Col1 = ActiveCell.Column
Wb1.Worksheets("Gains Data").Range(Selection,
Selection.End(xlToRight)).Select
'Col2 = ActiveCell.Column
Selection.Copy
'Windows("Gains SOP Forecast Comparison 2019 07.xlsb").Activate
Wb1.Sheets("Gains Data").Activate
'Range("O1:X1").Select
'Selection.AutoFill Destination:=Range(Col1 & Row1 & ":" & Col2 & Row2),
Type:=xlFillDefault
'Range("BA3:B" & LastRow1 & ":" & "CJ3:CJ" & LastRow1).Formula=
'Cells(Col1 & Row1 & ":" & Col2 & Row2).Paste
'Sheets("Gains Data").Range(Col1 & row3 & ":" & Col1 & Row2).Select
Wb1.Sheets("Gains Data").Range(Cells(row3, Col1), Cells(Row2,
Col1)).Select
ActiveSheet.Paste ' Copies the formulas from BA to CJ for all rows
The formulas should be copied down to all the rows depending on number of rows Wb2 has which I am storing in the row2 variable.