Insert Variable into Formula

RLJ

Active Member
Joined
Mar 15, 2011
Messages
417
Office Version
  1. 365
Platform
  1. Windows
I need to figure out how to modify the VBA below to have my variable populate in the formula that is being written into the cell.
VBA Code:
Sub Test()
Dim mth As Variant
mth = Range("NSDateMonths").Value
    
    With Range("U18")
    .FormulaR1C1 = _
        "=DATE(YEAR(Origination_Date),MONTH(Origination_Date)+mth,DAY(Origination_Date))"
    Range("U19").Select

Range("U19").Value = mth

End Sub

Thank you for your help
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try this

VBA Code:
Sub Test()
    Dim mth As Variant
    mth = Range("NSDateMonths").Value  ' make sure this is a number

    Range("U18").Formula = _
        "=DATE(YEAR(Origination_Date),MONTH(Origination_Date)+" & mth & ",DAY(Origination_Date))"
    Range("U19").Value = mth

End Sub
 
Upvote 0
Try this

VBA Code:
Sub Test()
    Dim mth As Variant
    mth = Range("NSDateMonths").Value  ' make sure this is a number

    Range("U18").Formula = _
        "=DATE(YEAR(Origination_Date),MONTH(Origination_Date)+" & mth & ",DAY(Origination_Date))"
    Range("U19").Value = mth

End Sub
Thank you, That Worked.
 
Upvote 0

Forum statistics

Threads
1,215,107
Messages
6,123,127
Members
449,097
Latest member
mlckr

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