Please help with simple function

D

Dylan

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 formula
IF(COUNTIF(B2,"<Z*"),0,IF(F2>0,(F2+$F$270+(IF(G2>0,G2+$G$270,0))-(H2+$H$270)),IF(G2>0,(G2+$G$270+(IF(F2>0,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
 
D

Dylan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top