Copy a formula down in VBA

dragontbone

New Member
Joined
Sep 28, 2022
Messages
37
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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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