Copy a formula down in VBA

dragontbone

New Member
Joined
Sep 28, 2022
Messages
35
Office Version
  1. 365
Platform
  1. Windows
Im trying to copy down a formula down in VBA using the following code.

VBA Code:
Sub offsetConcatenate()

' This will add the concatenate formula


Dim row As Integer
    Dim DateCountCalculator As Integer
    Dim MinusStart As String

DateCountCalculator = Range("DateCountCalculator").Value

For row = 1 To DateCountCalculator
    
   
    
    MinusStart = Range("Start_Date_Calculator").offset(row - 1, 4).Select
    
    ActiveCell.FormulaR1C1 = _
        "=CONCAT(Start_Date_Calculator&ConcatenateDateStart&TEXT(RC[-3],""MM/DD/YYYY""))"
    
 Next row


End Sub

I want it to be dynamic enough to know when to stop copying down the formula, but I can't get the formula to copy down the list of data I have without just copying the first line all the way down the list.
 
Try either
VBA Code:
Sub offsetConcatenate()

    ' This will add the concatenate formula

    Dim DateCountCalculator As Integer
    Dim MinusStart As Range

    DateCountCalculator = Range("DateCountCalculator").Value


    
    Set MinusStart = Range("Start_Date_Calculator").Offset(-1, 4)
    
    MinusStart.Resize(Range("DateCountCalculator")).FormulaR1C1 = _
          "=OFFSET(Start_Date_Calculator,ROWS(R1C1:R[-6]C1)-1,0) & "" - "" & TEXT(R[1]C[-3],""MM/DD/YYYY"")"
    
End Sub
or
VBA Code:
Sub offsetConcatenate2()

    ' This will add the concatenate formula

    Dim DateCountCalculator As Integer
    Dim MinusStart As Range

    DateCountCalculator = Range("DateCountCalculator").Value


    
    Set MinusStart = Range("Start_Date_Calculator").Offset(-1, 4)
    
    MinusStart.Resize(Range("DateCountCalculator")).FormulaR1C1 = _
           "=OFFSET(Start_Date_Calculator,ROWS(R1C1:R[-6]C1)-1,0) & ""  "" & R[1]C[-2] & "" "" & TEXT(R[1]C[-3],""MM/DD/YYYY"")"
    
End Sub
 
Upvote 0
Solution

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try either
VBA Code:
Sub offsetConcatenate()

    ' This will add the concatenate formula

    Dim DateCountCalculator As Integer
    Dim MinusStart As Range

    DateCountCalculator = Range("DateCountCalculator").Value


   
    Set MinusStart = Range("Start_Date_Calculator").Offset(-1, 4)
   
    MinusStart.Resize(Range("DateCountCalculator")).FormulaR1C1 = _
          "=OFFSET(Start_Date_Calculator,ROWS(R1C1:R[-6]C1)-1,0) & "" - "" & TEXT(R[1]C[-3],""MM/DD/YYYY"")"
   
End Sub
or
VBA Code:
Sub offsetConcatenate2()

    ' This will add the concatenate formula

    Dim DateCountCalculator As Integer
    Dim MinusStart As Range

    DateCountCalculator = Range("DateCountCalculator").Value


   
    Set MinusStart = Range("Start_Date_Calculator").Offset(-1, 4)
   
    MinusStart.Resize(Range("DateCountCalculator")).FormulaR1C1 = _
           "=OFFSET(Start_Date_Calculator,ROWS(R1C1:R[-6]C1)-1,0) & ""  "" & R[1]C[-2] & "" "" & TEXT(R[1]C[-3],""MM/DD/YYYY"")"
   
End Sub
Both of those worked for me! Thank you so much for the help. I really appreciate it!
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,981
Members
449,058
Latest member
oculus

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top