EXCEL怎么用VBA设置多层if函数条件
能不能编段代码看看?。。。我是初学者。。 展开
Function zhekou(zhanyoulv As Double, t As Integer)
If zhanyoulv < 0.035 Then
If t <= 15 Then
zhekou = 0
Else
If t <= 30 And t > 15 Then
zhekou = 0
Else
If t > 30 Then
zhekou = 0
End If
End If
End If
Else
If zhanyoulv >= 0.035 And zhanyoulv <= 0.04 Then
If t <= 15 Then
zhekou = 0.8
Else
If t <= 30 And t > 15 Then
zhekou = 1.2
Else
If t > 30 Then
zhekou = 1.5
End If
End If
End If
你可以这样试一试
Else
If zhanyoulv > 0.04 And zhanyoulv <= 0.045 Then
If t <= 15 Then
zhekou = 1
Else
If t <= 30 And t > 15 Then
zhekou = 1.5
Else
If t > 30 Then
zhekou = 2
End If
End If
End If
End If
End If
End If
End Function
Excel
Microsoft Excel是微软公司的办公软件Microsoft office的组件之一,是由Microsoft为Windows和Apple Macintosh操作系统的电脑而编写和运行的一款试算表软件。Excel 是微软办公套装软件的一个重要的组成部分,它可以进行各种数据的处理、统计分析和辅助决策操作,广泛地应用于管理、统计财经、金融等众多领域。
权当A1为占有率、B1为重量、折扣输出到C1单元格
Sub test()
Dim L, T, X
L = Range("A1")
T = Range("B1")
If L < 0.035 Then
If T <= 15 Then
X = 0
ElseIf L < 30 Then
X = 0
Else
X = 0
End If
ElseIf L < 0.04 Then
If T <= 15 Then
X = 0.8
ElseIf L < 30 Then
X = 1.2
Else
X = 1.5
End If
ElseIf L < 0.045 Then
If T <= 15 Then
X = 1
ElseIf L < 30 Then
X = 1.5
Else
X = 2
End If
ElseIf L < 0.055 Then
If T <= 15 Then
X = 1.5
ElseIf L < 30 Then
X = 2.5
Else
X = 3.5
End If
ElseIf L < 0.065 Then
If T <= 15 Then
X = 2
ElseIf L < 30 Then
X = 3
Else
X = 4
End If
ElseIf L < 0.08 Then
If T <= 15 Then
X = 2.5
ElseIf L < 30 Then
X = 3.5
Else
X = 4.5
End If
Else
If T <= 15 Then
X = 3
ElseIf L < 30 Then
X = 4
Else
X = 5
End If
End If
Range("C1") = X
End Sub
If zhanyoulv < 0.035 Then
If t <= 15 Then
zhekou = 0
Else
If t <= 30 And t > 15 Then
zhekou = 0
Else
If t > 30 Then
zhekou = 0
End If
End If
End If
Else
If zhanyoulv >= 0.035 And zhanyoulv <= 0.04 Then
If t <= 15 Then
zhekou = 0.8
Else
If t <= 30 And t > 15 Then
zhekou = 1.2
Else
If t > 30 Then
zhekou = 1.5
End If
End If
End If
Else
If zhanyoulv > 0.04 And zhanyoulv <= 0.045 Then
If t <= 15 Then
zhekou = 1
Else
If t <= 30 And t > 15 Then
zhekou = 1.5
Else
If t > 30 Then
zhekou = 2
End If
End If
End If
End If
End If
End If
End Function
对是对了,不过用select case编的话会简洁点,谢谢
=IF(AND(A1>=1501,A1<=2000),A1*5%,IF(AND(A1>=2001,A1<=3000),A1*10%,IF(A1>3001,A1*20%,0)))
给你个例子,自己学习一下