Copying a formula from Spreadsheet to VBA

  • Hi, I've entered the following formula into cell A2 ($D$17*(1-D21)). It copies down to the cell I want it to if I do it manually. I want it to copy down the number of times using a macro automatically. The number of times it should copy to is represted in cell I2. How should I go about doing this?


    Thanks much appreciated.

  • Re: Copying a formula from Spreadsheet to VBA


    Something like this should work


    Code
    Option Explicit
    
    
    Sub CopyFormula()
    Dim i As Long, C As Long
    C = Range("I2").Value
    For i = 2 To C + 1
    Cells(i, 1) = "=($D$17*(1-D" & 19 + i & "))"
    Next i
    End Sub
  • Re: Copying a formula from Spreadsheet to VBA


    Something like this?


  • Re: Copying a formula from Spreadsheet to VBA


    Hi buddy this might get you started, need a lot of error checks or might fails ie if i2 is empty or not whole number, give it a try.


    Jack


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!