need help on IIf

Fitz

New Member
Joined
May 29, 2003
Messages
25
The following IIf statment =IIf([Total Hours]<=26.4,[Total Hours]*[Daily]/8) is what i have in a report and works. However i want to continue this IIf. Can you help me with the following IIF =IIf([Total Hours]<=26.4,[Total Hours]*[Daily]/8),IIf([Total Hours]<=40,[Daily]*3,IIf([Total Hours]<=119,[Total Hours]*[Weekly]/40,IIf([Total Hours]<=176,[Monthly]*3,IIf([Total Hours]>=177,[Total Hours]*[Monthly]/176)))))

javascript:emoticon(':help:')
Help
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
looks like you have your first closed parenthesis too soon

try this maybe?

=If([Total Hours]<=26.4,[Total Hours]*[Daily]/8,IIf([Total Hours]<=40,[Daily]*3,IIf([Total Hours]<=119,[Total Hours]*[Weekly]/40,IIf([Total Hours]<=176,[Monthly]*3,IIf([Total Hours]>=177,[Total Hours]*[Monthly]/176)))))
 
Upvote 0
Hi Fitz,

Might I suggest a UDF?

Go the VB editor, insert a module, and paste in code like this:
Code:
Function FXhours(FXtotal, FXmonthly, FXweekly, FXdaily)

Select Case FXtotal
    Case Is <= 26.4
        FXhours = FXtotal * FXdaily / 8
    Case Is <= 40
        FXhours = FXdaily * 3
    Case Is <= 119
        FXhours = FXtotal * FXweekly / 40
    Case Is <= 176
        FXhours = FXmonthly * 3
    Case Is >= 177
        FXhours = FXtotal * FXmonthly / 176
End Select

End Function

You will use this function like any standard Access function, like in your report:
=FXHours([TxtTotal],[TxtMonthly],[TxtWeekly],[TxtDaily])

The arguments will be controls that house these respective values (TxtTotal would hold Total Hours).

You could probably modify your original function to do what you need, but this just seems so much clearer to me...

Adjust the arguments as necessary for your needs.

Also, avoid naming anything with spaces, that will invariably cause problems down the road.


HTH,
 
Upvote 0
Thanks Jobb and Corticus
,
I 'am a newbie I see my mistake in the formula.

I would like to use the UDF, I can type it in but I have no idea how to apply in my report.

Corticus could you give me an example

Thanks
 
Upvote 0
Sure Fitz,

Once you get the hang of using a UDF, you will love them (at least I do).

Insert the code in a standard module (alt+F11, insert|module, double click on the new module and insert paste in the code)

What you've done is make yourself a new formula, called FXhours(). It has four arguments, Total Hours, monthly, weekly, and daily.

If you use this in a report, you would use it like:
=FXHours([Total Hours], [monthly], [weekly], and [daily]). You would refer to these fields just as you were attempting to in your original formula.

You would replace [Total Hours] with the field in the report or query that contained this data.

To simplify, say you made a UDF (user defined function) that had two arguments. The function is Adder(arg1, arg2).

You might define it like:
Code:
Function Adder(arg1, arg2)
Adder = arg1 + arg2
End Function

And you would use the function like:
Adder(1,5) which would result in 6
or
Adder([field1],[field2]) which would add the data in field1 plus field2
or
Adder([txt1],[txt2]) which would add the number in Txt1 to Txt2.

I'll work it into a db if you need, just send it to
corticus@theofficeexperts.com (all data is confidential)

Its hard to provide a good sample for you without seeing how you intend to use it, but I'm pretty sure this UDF will get the job done for you.

HTH,
 
Upvote 0

Forum statistics

Threads
1,223,534
Messages
6,172,891
Members
452,487
Latest member
ISOmark26

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top