我正在尝试根据交货状态计算运费成本作为起始位置。多个州将使用相同的公式。我关注的代码部分位于
之下Dim STATE As String
Dim PLANT As String
Dim MILES As Integer
STATE = Range("STATE").Value
PLANT = Range("PLANT").Value
MILES = Range("MILES").Value
If STATE = "AL" Then
If PLANT = ("PLANT") Then
Result = (((MILES - XXX) * XXX) + XXX)
Range("FREIGHT") = Result
STATE条目单元格由列表框控制,我需要检查多个状态。即AL,AZ,AR等。如果不反复写If STATE = XX
,最好的方法是什么?
答案 0 :(得分:1)
修改强>
我不确定你到底想要做什么,但我认为你的意思是多个案例会“产生”相同的公式。
以下是使用Select ... Case:
的简单示例Select Case STATE
' Put here all the states that is in the first group.
Case "AL", "BL", "CL","DL"
' Code for the first group.
Case "EL","FL","GL","HL"
' Code for the second group.
End Select