Adding formulas to cells
Tom, Sorry I wasted your time. When I pasted the code in I must have grabbed
too much. It reads as follows:
Call InsertFormula(GetRowCount("C"), 20, "=IF(AB#=""1"",S#,
IF(AB#=""3"",N#/W#/100,"""")")
If you can still help, I would appreciated it. I think it has to do with
the use of * and / as all the other lines that work dont use multiple or
divide.
This is an example that does work:
Call InsertFormula(GetRowCount("C"), 15,
"=IF(ISERROR(FIND(""$"",S#,1))=TRUE,P#,"""")")
Again, sorry for sending the wrong code.
"Tom Ogilvy" wrote:
Your formula has an extra Parenthesis in it:
Instead of:
Call InsertFormula(GetRowCount("C"), 20,
"=IF(AB#=""1"",S#,IF(AB#=""3"",N#/W#/100,""""))=SUM(T#*V#))")
try
Call InsertFormula(GetRowCount("C"), 20,
"=IF(AB#=""1"",S#,IF(AB#=""3"",N#/W#/100,""""))=SUM(T#*V#)")
--
Regards,
Tom Ogilvy
"Jordan" wrote:
I am trying to add the following formual to a column of cells in Excel. The
code first goes through and counts the number of rows and then adds the
formula. We have used this many time before but are unable to get this one
to work. I have narrowed it down to it not working on the ones that use "*"
and/or "/" in them. Can anyone help me with this?
I posted this Friday and didnt get a response, so I am trying to clarifiy
and simplify my question. Any and all help will be greatly appriciated.
One that does work:
Call InsertFormula(GetRowCount("C"), 15,
"=IF(ISERROR(FIND(""$"",S#,1))=TRUE,P#,"""")")
One that does not work:
Call InsertFormula(GetRowCount("C"), 20,
"=IF(AB#=""1"",S#,IF(AB#=""3"",N#/W#/100,""""))=SUM(T#*V#))")
This is some of the code we use before using the lines above:
Private Function GetRowCount(strColumn As String) As Integer
Dim iCount As Long
Dim i As Long
For i = 1 To 65000
If Range(strColumn & i).Value < "" Then
iCount = iCount + 1
Else
Exit For
End If
Next
GetRowCount = iCount
End Function
Private Sub InsertFormula(intRowCount As Long, intColumn As Long, strFormula
As String)
Dim ws As Worksheet
Set ws = ThisWorkbook.ActiveSheet
For i = 2 To intRowCount
ws.Cells(i, intColumn) = Replace(strFormula, "#", CStr(i))
Next
End Sub
|