473,408 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Formula with Interop.excel do not work

When i use the following code with interop.excel

Expand|Select|Wrap|Line Numbers
  1.             rng = wsDiagram.get_Range("B4", missing);
  2.  
  3.             rng.Formula = "=AVERAGE(B1:B3)"; // OR "=SUM(B1:B3)"; 
  4.             rng.Calculate();
  5.  
The Cell shows #name?
When i hit the fomula bar suddenly te #name? goes away and the formula works.

Very strange, it happens with all the formulas in de Worksheet :-(
And the follwing code works fine filling the cells

Expand|Select|Wrap|Line Numbers
  1.  
  2. rng = wsDiagram.get_Range("B4", missing);
  3. rng.Formula = "=B1"; 
  4. //OR
  5. rng.Value2 = 43443512;
  6.  
  7.  
Can someone help me?

According to MSDN i'm doing it good, but it doesnt work.

PS: i dont get any error messages
Dec 5 '08 #1
5 7567
Ramk
61
Try expanding the column before setting your data.
Dec 7 '08 #2
I dont see why Expanding should fix the problem with not calculating the Formula. But i tried it and it didnt work. :-(

It looks more like Excel thinks it is a String and later realizes that it is a Formula when i press enter in the Formula Bar.

I found out when i read a Excel sheet and write it back in an other one the a Formula just works fine. I think i forget some propertie of method ???

But i still have the same problem.
Dec 8 '08 #3
Ramk
61
I have a small sample which doesn't give the error reported by you.
Instead if the range B1 to B2 doesn't contain any value, then for the formula "=AVERAGE(B1:B3)" gave #DIV/0! error which is logical.

Expand|Select|Wrap|Line Numbers
  1. Range range22 = worksheet.get_Range("B1", "B3");       
  2. range22.Value2 = 6;
  3. rng = worksheet.get_Range("B4", Missing.Value);
  4. rng.Formula = "=AVERAGE(B1:B3)"; // OR "=SUM(B1:B3)";
  5. rng.Calculate();
Alternative try this:
Expand|Select|Wrap|Line Numbers
  1. // Try this...
  2. 1)rng.Formula = "=AVERAGE(B$1:B$3)";
  3. In this case, if you apply this formula to more than 1col,
  4. still the new cells also contain the same avg formula
  5. from B1 to B2 as.
  6. 2)rng.Formula = "=AVERAGE($B1:$B3)";
  7. In this case, if you apply this formula to more than 1col,
  8. the new cells contain the avg formula based on new cells.
  9. ie B5 holds "=AVG(B2:B4)"
Still if you are unable to solve the problem, plz do post
little more code.
Dec 8 '08 #4
Thx for the info.

I tested it and i got exact the same problem whit your short code.
When the program opens the Sheet you made (your code) i get:

---------------------------------------
6
6
6
#name?

---------------------------------------

With you code i get the same problem, do you get the Formula good?

See my problem with my made workflow :-) (image)
Attached Images
File Type: jpg NAME.jpg (12.2 KB, 456 views)
Dec 8 '08 #5
Ramk
61
@Toine DB
I believe you are using Office2007. I am using Office2003.So, the same piece of code is working on Office2003 but not on Office2007.
Can you check the excel library which you are referring in your code!
Do try this...
Expand|Select|Wrap|Line Numbers
  1. rng = worksheet.get_Range("G4", Missing.Value);
  2. Instead of printing below(in B4 cell) the selected range
  3. values, try to print horizontally and see whether it can
  4. help you.
Dec 9 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bob N5 | last post by:
I am working on an application that uses interop to do some simple operations with both Excel and Word. I have most of functionality working, but ran into issues on making things work with both...
9
by: Maik | last post by:
Hello, I've developed an assembly, which opens an excel workbook and readout the range names and -values. I'm working with Office XP on my computer. I want to deploy this assembly on computers,...
4
by: Robert | last post by:
I have created a .dll in C# which has a reference to Excel. When I add a strong name to the .dll in the AssemblyInfo.cs and try to rebuild, I get the following error: Assembly generation failed...
2
by: Mike Eaton | last post by:
Hi all, I've created a vb.net app that opens and manipulates an excel file. The app works great on my system where I have all of the interop assemblies installed for visual studio. When I go...
1
by: Geoff | last post by:
Hello I am having an issue with my code below not closing EXCEL.EXE when I tell it do. Any help would be appreciated. ----- Dim excel As Microsoft.Office.Interop.Excel.Application Dim wb...
2
by: GS | last post by:
I have installed the ms PIA for ofc XP, and followed the article http://support.microsoft.com/kb/247412/ trying to paste into a worksheet However I got late binding not allowed errors .......
1
by: barnzee | last post by:
Hi all, newbie here, but having a go I am trying to build a stock watchlist in excel 2007 with a dynamic link to a DDE server (paid for from a broker).There is no add-in or plug-in, I just CTL ALT...
3
by: ianlukekane | last post by:
I've spent the past few weeks looking into various reporting mechanisms that will enable our company to create automated Excel reports in a "better" way. Currently, we're running a copy of Excel...
2
by: welshkaiboy | last post by:
Due to the size of the data I have to manipulate I need to apply a excel formula in access which determines date of manufacture from a serial number 716001 so I use...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.