Home > Software design >  Excel SQL Paste Formula down in column based on range of another column
Excel SQL Paste Formula down in column based on range of another column

Time:02-10

I have a spreadsheet that will populate data in Column A beginning at A2 from a table. Column A may be 10 rows or 150 Rows. I have a calculation in column F. I would like to Copy Down a formula in column F based on the number of Rows in Column A.

My code will copy a fixed range however I don't know how to make it dynamic based on the number of rows in column A.

Sheets("PriceAdjTemplate").Activate
Range("F2").Select
ActiveCell.Formula = "=(C2-E2)/C2"
Range("F2").Select
Selection.AutoFill Destination:=Range("F2:F350"), Type:=xlFillDefault

I would need to replace F350 with F & Number of rows in Column A Beginning with A2 Selection.AutoFill Destination:=Range("F2:F350"), Type:=xlFillDefault

CodePudding user response:

using your coding approach, change the Selection.Autofill as follows:

Sheets("PriceAdjTemplate").Activate
Range("F2").Formula = "=(C2-E2)/C2"
Range("F2").Select
Selection.AutoFill Destination:=Range("F2:F" & Range("A2").End(xlDown).Row), Type:=xlFillDefault
  • Related