Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating an Excel Value from Excel

Status
Not open for further replies.

campbere

Technical User
Oct 10, 2000
146
US
I am trying to calculate the values of three cells in Excel from VB.

I have the following:

with excelcalculations
.Cells("B17").Value = "=(5*5)"
.Cells("C17").Value = "=Sum(C2:C16)"
.Cells("D17").Formula = "=Sum(D15:D16)"
end with

None of these cells are getting populated using this convention. Any suggestions?

Thanks
 
First, the Cells object requires column and row indecies. If you want to specify cells as you have ("B17") you need to use the Range Object.
Code:
Range("B17").FormulaR1C1 = "=(5*5)"
or
Cells(17, 2).FormulaR1C1 = "=(5*5)"
 
In the past I have had to force the cells to evaluate an expression sent from VB using something like:

Cells("A1").Value = "=$E$1+$E$4"
Range("A1").Calculate
Colin Chevrier
colin.chevrier@ca.jdsuniphase.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top