View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
dylan dylan is offline
external usenet poster
 
Posts: 26
Default Please help with simple function

Here is what I have:

Function SumInvoice(myC As Range) As String
Dim Est As Long
Dim Fore As Long
Dim Prev As Long

Est = myC.Offset(0, 3).Value + Cells("K134")
Fore = myC.Offset(0, 4).Value + Cells("K135")
Prev = myC.Offset(0, 5).Value + Cells("K136")

With myC
If .Cells.Value < 0 Then
SumInvoice = ""

ElseIf Est 0 Or Fore 0 Then
SumInvoice = (Est + Fore) - Prev

Else: SumInvoice = 0

End If
End With

End Function

"Dylan" wrote:

I'm trying to create a function which will replace a formulae containing
nested If statements. I'm looking for some help, because I don't have much
experience with Functions.

Here is the cell formulae
IF(COUNTIF(B2,"<Z*"),0,IF(F20,(F2+$F$270+(IF(G20 ,G2+$G$270,0))-(H2+$H$270)),IF(G20,(G2+$G$270+(IF(F20,F2+$F$270 ,0))-(H2+$H$270)),"")))

It applies the following logic to each row, presenting a result in Cell I of
each row.
With each column in F-H, If the Cell 2 value is greater than 0, add Cell 2
to Cell 270. Then apply (F+G)-H to calculate the result.

I'm stuck at the beginning with cells containing text.
'If the cell value is text then the result = 0
If myC.Value < "Z" Then SumInvoice = 0 'doesn't work?

Dylan