Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 18
Default Trying To Put IFs into a Function


Ihave one thing I do in a formula that I don't know or haven't figured
out how to make it work in a function.

The formula looks like this:

IF(AND(299<Week1!$H3,Week1!$H3<350),4,0))+
(IF(AND(349<Week1!$H3,Week1!$H3<400),6,0))+
(IF(AND(399<Week1!$H3,Week1!$H3<450),8,0))+
(IF(AND(449<Week1!$H3,Week1!$H3<500),10,0))+
(IF(Week1!$H3499,12,0)

Simply put, it looks at the value in Worksheet named Week1 - cell H3
(could be H4, H5, H6 depending, also could be Week2 - 17) ) and if
that number falls within the listed values, it awards points.

Any help putting that into a function that will work with the Week and
Offset shown above would be greatly appreciated.

In other words I'd like to have a function that looks like this:

=Bonus (W, Q)

Where the Function Bonus would look something like:

Public Function Bonus(W, Q)
? the incorporated IFs pointing to the proper cells
End Function

Here W is a number that would form the name of the Worksheet to look
at ("Week" & W) and Q would be the offset Pointing to cells starting
at H2 to pick up the value to analyze.

Any help would be most appreciated.

Thanks.

Steve
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default Trying To Put IFs into a Function

I think this UDF will do what you want...

Function Bonus(WeekNumber As Long, RowOffsetFromH2 As Long) As Double
Dim CellValue As Double
CellValue = Worksheets("Week" & WeekNumber).Range("H2"). _
Offset(RowOffsetFromH2).Value
Select Case CellValue
Case Is < 300
Bonus = 0
Case Is < 350
Bonus = 4
Case Is < 400
Bonus = 6
Case Is < 450
Bonus = 8
Case Is < 500
Bonus = 10
Case Else
Bonus = 12
End Select
End Function

Note that the RowOffsetFromH2 argument is numbered starting at 0 (for H2),
then going to 1 (for H3), 2 (for H4), etc.

--
Rick (MVP - Excel)


"SkippyPB" wrote in message
...

Ihave one thing I do in a formula that I don't know or haven't figured
out how to make it work in a function.

The formula looks like this:

IF(AND(299<Week1!$H3,Week1!$H3<350),4,0))+
(IF(AND(349<Week1!$H3,Week1!$H3<400),6,0))+
(IF(AND(399<Week1!$H3,Week1!$H3<450),8,0))+
(IF(AND(449<Week1!$H3,Week1!$H3<500),10,0))+
(IF(Week1!$H3499,12,0)

Simply put, it looks at the value in Worksheet named Week1 - cell H3
(could be H4, H5, H6 depending, also could be Week2 - 17) ) and if
that number falls within the listed values, it awards points.

Any help putting that into a function that will work with the Week and
Offset shown above would be greatly appreciated.

In other words I'd like to have a function that looks like this:

=Bonus (W, Q)

Where the Function Bonus would look something like:

Public Function Bonus(W, Q)
? the incorporated IFs pointing to the proper cells
End Function

Here W is a number that would form the name of the Worksheet to look
at ("Week" & W) and Q would be the offset Pointing to cells starting
at H2 to pick up the value to analyze.

Any help would be most appreciated.

Thanks.

Steve


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,533
Default Trying To Put IFs into a Function

Hi

I reduced your formula to this:

=IF(AND(299<Week1!$H3,Week1!$H3<350),4,IF(Week1!$H 3<400,6,IF(Week1!$H3<450,8,IF(Week1!$H3<500,10,12) )))



Public Function Bonus(W As Long, Q As Long) As Long
Dim TargetVal As Double
Application.Volatile
TargetVal = Worksheets("Week" & W).Range("H3").Offset(Q, 0)

Select Case TargetVal
Case Is < 300
Bonus = 0
Case Is < 350
Bonus = 4
Case Is < 400
Bonus = 6
Case Is < 450
Bonus = 8
Case Is < 500
Bonus = 10
Case Else
Bonus = 12
End Select
End Function

Regards,
Per

"SkippyPB" skrev i meddelelsen
...

Ihave one thing I do in a formula that I don't know or haven't figured
out how to make it work in a function.

The formula looks like this:

IF(AND(299<Week1!$H3,Week1!$H3<350),4,0))+
(IF(AND(349<Week1!$H3,Week1!$H3<400),6,0))+
(IF(AND(399<Week1!$H3,Week1!$H3<450),8,0))+
(IF(AND(449<Week1!$H3,Week1!$H3<500),10,0))+
(IF(Week1!$H3499,12,0)

Simply put, it looks at the value in Worksheet named Week1 - cell H3
(could be H4, H5, H6 depending, also could be Week2 - 17) ) and if
that number falls within the listed values, it awards points.

Any help putting that into a function that will work with the Week and
Offset shown above would be greatly appreciated.

In other words I'd like to have a function that looks like this:

=Bonus (W, Q)

Where the Function Bonus would look something like:

Public Function Bonus(W, Q)
? the incorporated IFs pointing to the proper cells
End Function

Here W is a number that would form the name of the Worksheet to look
at ("Week" & W) and Q would be the offset Pointing to cells starting
at H2 to pick up the value to analyze.

Any help would be most appreciated.

Thanks.

Steve


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Data Validation/Lookup function does function correcty Kirkey Excel Worksheet Functions 2 May 25th 09 09:22 PM
copy of excel file not showing formulal/function in the function b oaallam Excel Discussion (Misc queries) 4 September 6th 07 01:20 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Offset function with nested match function not finding host ss. MKunert Excel Worksheet Functions 1 March 21st 06 10:46 PM
Emulate Index/Match combo function w/ VBA custom function Spencer Hutton Excel Worksheet Functions 2 May 2nd 05 05:26 PM


All times are GMT +1. The time now is 03:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"