View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Umlas[_3_] Bob Umlas[_3_] is offline
external usenet poster
 
Posts: 320
Default Can I simplify this function

Function WhichBox(pIndex As Integer) As Integer
WhichBox = Application.Min(Int((pIndex + 3) / 4), 4)
End Function

Bob Umlas
Excel MVP


"Mike NG" wrote in message
...
Function WhichBox(piIndex As Integer) As Integer

If piIndex < 5 Then
WhichBox = 1
ElseIf piIndex < 9 Then
WhichBox = 2
ElseIf piIndex < 13 Then
WhichBox = 3
Else
WhichBox = 4
End If

End Function


I am going round in loops with / and mod - I am sure I can do it with
one line of code, but how do I do it please, i.e.

PiIndex Returns
1 to 4 1
5 to 8 2
9 to 12 3
13 to 16 4
--
Mike