Solved

Placing formula in Excel sheet from VFP

Posted on 2011-03-16
6
1,586 Views
Last Modified: 2012-05-11
Using the following code from VFP:

oExcel.Cells(6,14).FormulaR1C1 = "=AVERAGE(B6:M6)"

I get superfluous quotes put in to the formula which gives me an #NAME error in Excel. The formula gets received like this:

=AVERAGE('B6':'M6')

How can I prevent this?
0
Comment
Question by:AndrewJen
6 Comments
 
LVL 2

Expert Comment

by:Gary2Seven
ID: 35148130

I have always used ;

oExcel.Range("A1").Formula="=AVERAGE(B6:M6)"

and not had any issues.
0
 
LVL 12

Expert Comment

by:jrbbldr
ID: 35148222
This is just a guess, but every time I get an Excel error:   #NAME    it has been due to the contents of the cells themselves upon which the formula operates.

Try going into the Excel file manually (without any VFP involvement) and putting the formula into the desired cells and see what the result is.  

If you still get the error displayed, then it is the result of the cell contents that are being calculated - perhaps the Cell Type or the value within the cell(s).

Good Luck
0
 
LVL 27

Accepted Solution

by:
CaptainCyril earned 500 total points
ID: 35150084
You have to use relative addressing:

xlapp = CREATEOBJECT("Excel.Application")
xlapp.Visible = .T.
xlwb = xlapp.Workbooks.Add
xlsheet = xlwb.Sheets(1)
FOR i = 1 TO 10
	xlsheet.Cells(i,1).Value = i
ENDFOR
xlsheet.Cells(11,1).FormulaR1C1 = "=AVERAGE(R[-10]C:R[-1]C)"

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 3

Author Closing Comment

by:AndrewJen
ID: 35155580
Perfect, thank you!

Where might I find some documentation on this?
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 35155654
You're welcome!

I get it from Excel's Help. Sometimes I record macros from Excel and see how it works.

If I get lucky, I might find a good website MSDN or some other forum that describes the things I am looking for.

When you get stuck, EE is your best pal! You can ask the question in FoxPro and Excel sections.
0
 
LVL 12

Expert Comment

by:jrbbldr
ID: 35155760
"Sometimes I record macros from Excel and see how it works"

If I don't know how to do an Excel Automation, I ALWAYS do the work manually in Excel while recording the operations as a Macro.   Then, when done, examine the Macro to see how Excel did it.    That then 'tells' me what to do and how to do it in my VFP Automation.

AndrewJen - glad the Captain got you what you needed.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now