Simple Excel 2010 issue

Posted on 2013-10-30
Last Modified: 2013-10-30
This seems simple enough... This following code is attached to a button to clear some data on a spreadsheet...

    ActiveCell.FormulaR1C1 = "=DATE(YEAR(F3),MONTH(F3)+1,DAY(F3))-1"

The formula works fine but when it runs in code, Excel replaces the cell with this...

(Note the single quotes that are added)

If I edit the formula and remove the single quotes it works as expected but Excel is adding the single quotes when it inserts the formula.

How can I have Excel insert the code as I have written it??

Question by:DanielT
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 12

Expert Comment

by:Harry Lee
ID: 39612923

ActiveCell.FormulaR1C1 = "=DATE(YEAR(R3C6),MONTH(R3C6)+1,DAY(R3C6))-1"
LVL 50

Assisted Solution

by:barry houdini
barry houdini earned 100 total points
ID: 39612924
You are using "FormulaR1C1" but the notation in the formula is using conventional cell references, for R1C1 you need to make the references relative to H3 so because F3 is 2 columns before H3 that would be

ActiveCell.FormulaR1C1 = "=DATE(YEAR(RC[-2]),MONTH(RC[-2])+1,DAY(RC[-2]))-1"

regards, barry
LVL 12

Accepted Solution

Harry Lee earned 200 total points
ID: 39612930
Or you can use

 ActiveCell.Formula = "=DATE(YEAR(F3),MONTH(F3)+1,DAY(F3))-1"
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.


Author Comment

ID: 39612943
Thank you both.
I see that both methods work OK.

Is this simply because the "FormulaR1C1" property cannot accept conventional cell references?

Author Comment

ID: 39612954
I like the last example best. Thx HarryHYLee!

I think I started this code with an Excel Macro - could have been migrated from Excel 2003 as well.
LVL 12

Assisted Solution

by:Harry Lee
Harry Lee earned 200 total points
ID: 39612981

Yes, the difference between those two are cell reference format.

Activecell.Formula uses the A1 cell reference format, and
Activecell.FormulaR1C1 uses the R1C1 format. R? is the row #, and C? is the column #.

They are not compatible with each other, and will not accept the wrong type of cell references.

Author Comment

ID: 39612986
Thanks again!!

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Determine dependencies 3 21
Color a cell based on a date in Excel 8 23
PBI - need to format a new column with formula 6 14
Excel Pivot Table question 5 16
Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question