Forum

How do you get a fo...
 
Notifications
Clear all

How do you get a formula to paste when using Macro's?

3 Posts
3 Users
0 Reactions
167 Views
(@taph77hotmail-com)
Posts: 2
Active Member
Topic starter
 

Great news...found the answer...this works: ActiveCell.FormulaR1C1 = "=""01/01/""&YEAR(TODAY())"

 

How do you get a formula to paste when using Macro's? I need to insert the formula ="01/01/"&YEAR(TODAY()) into B15 using a macro.  Any help would be great!

Need:

    Range("B15").Select
    ActiveCell.FormulaR1C1 = "="01/01/"&YEAR(TODAY())"

Current:

    Sheets("VOI Calculations for Primary").Select

    Range("B9").Select
    ActiveCell.FormulaR1C1 = "*Enter current period Social Security*"
    Range("B10").Select
    ActiveCell.FormulaR1C1 = "*Enter current period Medicare*"
    Range("B15").Select
    ActiveCell.FormulaR1C1 = "01/01/2018"

 
Posted : 28/12/2018 9:09 am
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Troy

You can try

ActiveCell.Formula = "=Date(Year(Today()),1,1)"

or 

Range("B15").Formula = "=Date(Year(Today()),1,1)"

You don't need to select a cell before you insert the formula. Just refer to it, for e.g. Range("B15") etc

Hope this helps.

Sunny

 
Posted : 28/12/2018 8:48 pm
(@debaser)
Posts: 837
Member Moderator
 

Just to answer the specific issue you were having, you need to double up any quotes inside the actual formula, so it would be:

 

Range("B15").Formula = "=""01/01/""&YEAR(TODAY())"

 
Posted : 03/01/2019 11:20 am
Share: