?
Solved

Simple Excel 2010 issue

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

    Range("H3").Select
    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...
=DATE(YEAR('F3'),MONTH('F3')+1,DAY('F3'))-1

(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??

Thx!
0
Comment
Question by:DanielT
[X]
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
7 Comments
 
LVL 12

Expert Comment

by:Harry Lee
ID: 39612923
Daniel,


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

Assisted Solution

by:barry houdini
barry houdini earned 400 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
0
 
LVL 12

Accepted Solution

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

 ActiveCell.Formula = "=DATE(YEAR(F3),MONTH(F3)+1,DAY(F3))-1"
0
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 2

Author Comment

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

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

Author Comment

by:DanielT
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.
0
 
LVL 12

Assisted Solution

by:Harry Lee
Harry Lee earned 800 total points
ID: 39612981
Daniel,

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.
0
 
LVL 2

Author Comment

by:DanielT
ID: 39612986
Thanks again!!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

770 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