Simple Multiplication Formula
But it is a value not a formula. Formula might work, but Value helps explain
the intent
Public Function MultiplyCells(RowIdx As Long, _
ColOne As Long, _
ColTwo As Long, _
ResultCol As Long, _
oWs As Worksheet) As Boolean
With oWs
.Cells(RowIdx, ResultCol).Value= "=" & _
.Cells(RowIdx, ColOne).Address(False, False) & "*" & _
.Cells(RowIdx, ColTwo).Address(False, False)
End With
End Function
--
---
HTH
Bob
(there's no email, no snail mail, but somewhere should be gmail in my addy)
"MP" wrote in message
...
Fantastic!!!
Thank you so much for that prompt reply
That works beautifully!
It produces an "absolute" reference
example:
=$C$21*$D$21
which is fine for my current application....
just for my education, how would I change it to produce a "relative"
reference
=C21*D21
?
also is there a place in excel help where I should have been able to find
this?
or other good links for programatic object model info
Thanks again for the solution
Mark
:-)
"ilia" wrote in message
...
You want it to be like this, perhaps?
Public Function MultiplyCells(RowIdx As Long, _
ColOne As Long, _
ColTwo As Long, _
ResultCol As Long, _
oWs As Worksheet) As Boolean
With oWs
.Cells(RowIdx, ResultCol).Formula = "=" & _
.Cells(RowIdx, ColOne).Address & "*" & _
.Cells(RowIdx, ColTwo).Address
End With
End Function
On Dec 19, 1:50 pm, "MP" wrote:
I've been searching google for some time now and cant' find the answer
This is probably too simple a question
I'm trying to write a function that will put a formula in ResultCol to
multiply InputColOne times InputColTwo
Public Function MultiplyCells(RowIdx As Long, ColOne As Long, ColTwo As
Long, ResultCol As Long, oWs As Worksheet) As Boolean
oWs.Cells(RowIdx, ResultCol).FormulaR1C1 = oWs.Cells(RowIdx,
ColOne).Value
* oWs.Cells(RowIdx, ColTwo).Value
End Function
I'm sure my syntax is wrong, I don't clearly understand the .FormumaR1C1
method...
It's not throwing an error, but it's putting the value in the result
cell,
not the formula
any hints?
Thanks Mark
|