• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

VBA Error

Hi,

I have this code in the VBA Editor

ActiveCell.FormulaR1C1 = "=DATE(YEAR(Update!AB1),MONTH(Update!AB1),0)"

It produces an error in excel, the formula it drops out is

=DATE(YEAR(Update!'AB1'),MONTH(Update!'AB1'),0)

I notice if i take the apostrophes away from AB1, the formula works, how can i fix this in the editor?

Thanks
Seamus
0
Seamus2626
Asked:
Seamus2626
2 Solutions
 
Ingeborg Hawighorst (Microsoft MVP / EE MVE)Microsoft MVP ExcelCommented:
Hello,

Don't use the ActiveCell.FormulaR1C1 if you reference cells with the A1 style. Instead use

ActiveCell.Formula = "=DATE(YEAR(Update!AB1),MONTH(Update!AB1),0)"

and the formula in the cell will be fine.

cheers, teylyn
0
 
jppintoCommented:
Put .Formula instead, like this:

ActiveCell.Formula= "=DATE(YEAR(Update!AB1),MONTH(Update!AB1),0)"

0
 
Seamus2626Author Commented:
Thanks guys
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now