It is amazing how “else” in separate line makes the difference, your help was really appreciated and I would love to buy you lunch if I can, you made my day.
Thank you
Coach z
Excel UDF Function if Statement giving me error
Hello , The UDF function works only for one of the conditions and errors if there is more than one, using else if did not want to work, What am I doing wrong? Thank you
Function Calc(rowaddress)
If (cells(rowaddress.row,6).value="F" or cells(rowaddress.row,6).value="P" _
And cells(rowaddress.row,16).value=0 _
And cells(rowaddress.row,10).value<24) _
then Calc=24-cells(rowaddress.row,10).value
Else If (cells(rowaddress.row,6).value="F" or cells(rowaddress.row,6).value="O" _
And cells(rowaddress.row,16).value<>0 _
And cells(rowaddress.row,10).value>24) _
then Calc=24+cells(rowaddress.row,10).value
else calc=0
I inherited a long formula that a function will do wonders with it, it has 9 different conditions, any help will be greatly appreciated.
Thank you
Windows for business Windows Client for IT Pros User experience Other
-
coach z 96 Reputation points
2021-05-22T19:52:57.79+00:00
2 additional answers
Sort by: Most helpful
-
coach z 96 Reputation points
2021-05-22T03:11:06.91+00:00 Thank you.
Error says end without if block, when I look at the code the system change my Else if to Else: If.
The formula works only when I leave only the first condition and remove the others, others comes with #value! In the cell result.
Appreciate your help. -
MotoX80 36,291 Reputation points
2021-05-22T12:36:54.323+00:00 VBA is ElseIf.
https://www.educba.com/vba-else-if/
Function Calc(rowaddress) If ((cells(rowaddress.row,6).value="F" or cells(rowaddress.row,6).value="P") And cells(rowaddress.row,16).value=0 And cells(rowaddress.row,10).value<24) then Calc=24-cells(rowaddress.row,10).value ElseIf ((cells(rowaddress.row,6).value="F" or cells(rowaddress.row,6).value="O") And cells(rowaddress.row,16).value<>0 And cells(rowaddress.row,10).value>24) then Calc=24+cells(rowaddress.row,10).value else calc=0 End if End Function