View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen[_2_] Per Jessen[_2_] is offline
external usenet poster
 
Posts: 703
Default Help with IF... Then... Else statement

Hi

Look at this: (I will leave it to you to rewrite your second IF
statement.)

Public Function GroundCover(Input1 As String, Input2 As Integer,
Input3 As Double)

' Determine if input1 = flats
If Input1 = "Flats" Then
'Use Select Case input2 and multiply input3 by coresponding Number
Select Case Input2
Case Is = 4
Output = Input3 * 0.1406
Case Is = 6
Output = Input3 * 0.0625
Case Is = 8
Output = Input3 * 0.0351
Case Is = 9
Output = Input3 * 0.0278
Case Is = 10
Output = Input3 * 0.0225
Case Is = 12
Output = Input3 * 0.0156
Case Is = 18
Output = Input3 * 0.0087
Case Is = 24
Output = Input3 * 0.0039
Case Is = 30
Output = Input3 * 0.0025
Case Else
Output = 0
End Select
Else
'Use second IF statement to check input1 and multiply input3 by
coresponding Number
'Output=(IF(input2=4,input3*9, IF(input2=6,input3*4,
'IF(input2=8,input3*2.25, IF(input2=9,input3*1.78,
IF(input2=10,input3*1.44,
'IF(input2=12,input3, IF(input2=16,input3*0.56,
IF(input2=18,input3*0.45,
'IF(input2=24,input3*0.25, IF(input2=30,input3*0.16,
'IF(input2=36,input3*0.1111, IF(input2=48,input3*0.0625,
'IF(input2=72,input3*0.0278,"0")))))))))))))
End If
GroundCover = Output
End Function

Regards,
Per

On 9 Okt., 00:21, Nick VL wrote:
I originally was going to do this just as a standard (albeit long) function
in Excel, but quickly had more nested levels then allowed. *So my hope is
that I can in VBA produce a custom function that will do all of the work and
be compatible with 2003 xls format. *Please let me know if this is possible
and if there is a better approach to this. *Below is the VBA that I have so
far, that obviously does not work Im not sure how to use/insert the excel IF
statements. *Thanks for ANY help.

Public Function GroundCover()
'Create Variables to hold numbers
Dim input1 As Double
Dim input2 As Double
Dim input3 As Double

'Fill the variables with input from the worksheet
input1 = Worksheet.cels(27, 2)
input2 = Worksheet.Cells(27, 3)
input3 = Worksheet.Cells(27, 4)
' Determine if input1 = flats
If input1 = "Flats" Then

* * 'Use IF statement to check input2 and multiply input3 by coresponding
number
* * Output=(IF(input2=4,input3*0.1406, IF(input2=6,input3*0.0625,
IF(input2=8,input3*0.0351, IF(input2=9,input3*0.0278,
IF(input2=10,input3*0.0225, IF(input2=12,input3*0.0156,
IF(input2=18,input3*0.0087, IF(input2=24,input3*0.0039,
IF(input2=30,input3*0.0025,"0"))))))))))

Else
* * 'Use second IF statement to check input1 and multiply input3 by
coresponding number
* * Output=(IF(input2=4,input3*9, IF(input2=6,input3*4,
IF(input2=8,input3*2.25, IF(input2=9,input3*1.78, IF(input2=10,input3*1.44,
IF(input2=12,input3, IF(input2=16,input3*0.56, IF(input2=18,input3*0.45,
IF(input2=24,input3*0.25, IF(input2=30,input3*0.16,
IF(input2=36,input3*0.1111, IF(input2=48,input3*0.0625,
IF(input2=72,input3*0.0278,"0")))))))))))))

End If

End Function