Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Simple Excel 2010 issue

Posted on 2013-10-30
7
Medium Priority
?
233 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

636 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