【发布时间】:2018-04-03 01:26:18
【问题描述】:
我正在提高两个宏的效率。除了标题中描述的方法之外,我已经设法改进了他们所有的方法。它功能齐全,但我确信有更好的方法来纠正我在下面提供的代码部分:
For Each cell2 In Range("L2:L" & lastrow2)
If Not cell2.Offset(0, -1).Value = 0 Then
If cell2.Offset(0, -5).Value = "SOCHACZEW" Then
cell2.Value = 31.2
ElseIf cell2.Offset(0, -5).Value = "SEKERPINAR" Then
cell2.Value = 33
ElseIf cell2.Offset(0, -5).Value = "ATHENS" Then
cell2.Value = 28
ElseIf cell2.Offset(0, -5).Value = "MECHELEN" Then
cell2.Value = 33
ElseIf cell2.Offset(0, -5).Value = "TIMISOARA" Then
cell2.Value = 34
ElseIf cell2.Offset(0, -5).Value = "STRANCICE" Then
cell2.Value = 33
ElseIf cell2.Offset(0, -5).Value = "KLIPPAN" Then
cell2.Value = 33
ElseIf cell2.Offset(0, -5).Value = "MATARO" Then
cell2.Value = 33
ElseIf cell2.Offset(0, -5).Value = "KIEV" Then
cell2.Value = 32
ElseIf cell2.Offset(0, -5).Value = "ROSTOV" Then
cell2.Value = 32.6
ElseIf cell2.Offset(0, -5).Value = "ITELLA" Then
cell2.Value = 32
End If
End If
Next cell2
【问题讨论】:
-
你可以用
Select Case cell2.Offset(0, -5).Value代替你的多个ElseIfs -
所以,我应该将 ElseIf 替换为 Select Case cell2.Offset(0, -5).Value ?
-
在下面查看我的答案和代码,看看是否对您有帮助
标签: vba excel for-loop if-statement