vba 中的嵌套 IF 输出不正确
Incorrect output with Nested IFs in vba
我希望 "TRUE" 仅当除总值之外的各个值也相等时才输出 values.I 我只是包含了一部分我没有得到正确输出的代码。
我正在尝试获取附件中的输出,但我收到以下代码的错误输出。请帮助我理解我的错误:
Dim aPRTS, bNIMS,d19, d8, d25, ud, p19, p8, p25, du19, du8, du25, AudLastCol,AudLastRow As Long
For l = 2 To AudLastRow
aPRTS = .Cells(l, AudLastCol).Value
bNIMS = .Cells(l, NIMsLastCol).Value
d19 = .Cells(l, Application.Match("Deployed(1.9)", .Range("A1:A" & AudLastCol), 0)).Value
d8 = .Cells(l, Application.Match("Deployed (800)", .Range("A1:A" & AudLastCol), 0)).Value
d25 = .Cells(l, Application.Match("Deployed (2.5)", .Range("A1:A" & AudLastCol), 0)).Value
p8 = .Cells(l, Application.Match("Total-800-PRTS", .Range("A1:A" & AudLastCol), 0)).Value
p19 = .Cells(l, Application.Match("Total-1900-PRTS", .Range("A1:A" & AudLastCol), 0)).Value
p25 = .Cells(l, Application.Match("Total-2500-PRTS", .Range("A1:A" & AudLastCol), 0)).Value
ud = .Cells(l, Application.Match("Deployed (Unassigned)", .Range("A1:A" & AudLastCol), 0)).Value
du19 = d19 + ud
du8 = d8 + ud
du25 = d25 + ud
If aPRTS = bNIMS Then
If (p19 = d19) And (p8 = d8) And (p25 = d25) Then
.Cells(l, AudLastCol + 1).Value = "TRUE"
.Cells(l, AudLastCol + 3).Value = "No Action required."
ElseIf (p19 = du19) And (p8 = d8) And (p25 = d25) Then
.Cells(l, AudLastCol + 1).Value = "TRUE"
.Cells(l, AudLastCol + 3).Value = "No Action required."
ElseIf (p19 = d19) And (p8 = du8) And (p25 = d25) Then
.Cells(l, AudLastCol + 1).Value = "TRUE"
.Cells(l, AudLastCol + 3).Value = "No Action required."
ElseIf (p19 = d19) And (p8 = d8) And (p25 = du25) Then
.Cells(l, AudLastCol + 1).Value = "TRUE"
.Cells(l, AudLastCol + 3).Value = "No Action required."
Else
.Cells(l, AudLastCol + 1).Value = "FALSE"
.Cells(l, AudLastCol + 2).Value = "Check Manually"
.Cells(l, AudLastCol + 3).Value = "Band wise Carrier Mismatch."
End If
End If
Next l
使用下面的代码:
Dim aPRTS, bNIMS, d19, d8, d25, ud, p19, p8, p25, du19, du8, du25, AudLastCol, AudLastRow As Long
For l = 2 To AudLastRow
aPRTS = .Cells(l, AudLastCol).Value
bNIMS = .Cells(l, NIMsLastCol).Value
d19 = .Cells(l, Application.Match("Deployed(1.9)", .Range("A1:A" & AudLastCol), 0)).Value
d8 = .Cells(l, Application.Match("Deployed (800)", .Range("A1:A" & AudLastCol), 0)).Value
d25 = .Cells(l, Application.Match("Deployed (2.5)", .Range("A1:A" & AudLastCol), 0)).Value
p8 = .Cells(l, Application.Match("Total-800-PRTS", .Range("A1:A" & AudLastCol), 0)).Value
p19 = .Cells(l, Application.Match("Total-1900-PRTS", .Range("A1:A" & AudLastCol), 0)).Value
p25 = .Cells(l, Application.Match("Total-2500-PRTS", .Range("A1:A" & AudLastCol), 0)).Value
ud = .Cells(l, Application.Match("Deployed (Unassigned)", .Range("A1:A" & AudLastCol), 0)).Value
du19 = d19 + ud
du8 = d8 + ud
du25 = d25 + ud
If aPRTS = bNIMS Then
If (p19 = d19 Or p19 = du19) And (p8 = d8 Or p8 = du8) And (p25 = d25 Or p25 = du25) Then
.Cells(l, AudLastCol + 1).Value = "TRUE"
.Cells(l, AudLastCol + 3).Value = "No Action required."
Else
.Cells(l, AudLastCol + 1).Value = "FALSE"
.Cells(l, AudLastCol + 3).Value = "Band wise Carrier Mismatch."
End If
End If
Next l
自 OP 的代码更改后进行编辑 (...)
你必须改变:
d19 = .Cells(l, Application.Match("Deployed(1.9)", .Range("A1:A" & AudLastCol), 0)).Value
至:
d19 = .Cells(l, Application.Match("Deployed(1.9)", .Rows(1).Resize(,AudLastCol), 0)).Value
实际在第 1 行搜索到 AudLastCol 列而不是从第 1 列搜索到 AudLastCol 行
与其他代码行相同
我希望 "TRUE" 仅当除总值之外的各个值也相等时才输出 values.I 我只是包含了一部分我没有得到正确输出的代码。 我正在尝试获取附件中的输出,但我收到以下代码的错误输出。请帮助我理解我的错误:
Dim aPRTS, bNIMS,d19, d8, d25, ud, p19, p8, p25, du19, du8, du25, AudLastCol,AudLastRow As Long
For l = 2 To AudLastRow
aPRTS = .Cells(l, AudLastCol).Value
bNIMS = .Cells(l, NIMsLastCol).Value
d19 = .Cells(l, Application.Match("Deployed(1.9)", .Range("A1:A" & AudLastCol), 0)).Value
d8 = .Cells(l, Application.Match("Deployed (800)", .Range("A1:A" & AudLastCol), 0)).Value
d25 = .Cells(l, Application.Match("Deployed (2.5)", .Range("A1:A" & AudLastCol), 0)).Value
p8 = .Cells(l, Application.Match("Total-800-PRTS", .Range("A1:A" & AudLastCol), 0)).Value
p19 = .Cells(l, Application.Match("Total-1900-PRTS", .Range("A1:A" & AudLastCol), 0)).Value
p25 = .Cells(l, Application.Match("Total-2500-PRTS", .Range("A1:A" & AudLastCol), 0)).Value
ud = .Cells(l, Application.Match("Deployed (Unassigned)", .Range("A1:A" & AudLastCol), 0)).Value
du19 = d19 + ud
du8 = d8 + ud
du25 = d25 + ud
If aPRTS = bNIMS Then
If (p19 = d19) And (p8 = d8) And (p25 = d25) Then
.Cells(l, AudLastCol + 1).Value = "TRUE"
.Cells(l, AudLastCol + 3).Value = "No Action required."
ElseIf (p19 = du19) And (p8 = d8) And (p25 = d25) Then
.Cells(l, AudLastCol + 1).Value = "TRUE"
.Cells(l, AudLastCol + 3).Value = "No Action required."
ElseIf (p19 = d19) And (p8 = du8) And (p25 = d25) Then
.Cells(l, AudLastCol + 1).Value = "TRUE"
.Cells(l, AudLastCol + 3).Value = "No Action required."
ElseIf (p19 = d19) And (p8 = d8) And (p25 = du25) Then
.Cells(l, AudLastCol + 1).Value = "TRUE"
.Cells(l, AudLastCol + 3).Value = "No Action required."
Else
.Cells(l, AudLastCol + 1).Value = "FALSE"
.Cells(l, AudLastCol + 2).Value = "Check Manually"
.Cells(l, AudLastCol + 3).Value = "Band wise Carrier Mismatch."
End If
End If
Next l
使用下面的代码:
Dim aPRTS, bNIMS, d19, d8, d25, ud, p19, p8, p25, du19, du8, du25, AudLastCol, AudLastRow As Long
For l = 2 To AudLastRow
aPRTS = .Cells(l, AudLastCol).Value
bNIMS = .Cells(l, NIMsLastCol).Value
d19 = .Cells(l, Application.Match("Deployed(1.9)", .Range("A1:A" & AudLastCol), 0)).Value
d8 = .Cells(l, Application.Match("Deployed (800)", .Range("A1:A" & AudLastCol), 0)).Value
d25 = .Cells(l, Application.Match("Deployed (2.5)", .Range("A1:A" & AudLastCol), 0)).Value
p8 = .Cells(l, Application.Match("Total-800-PRTS", .Range("A1:A" & AudLastCol), 0)).Value
p19 = .Cells(l, Application.Match("Total-1900-PRTS", .Range("A1:A" & AudLastCol), 0)).Value
p25 = .Cells(l, Application.Match("Total-2500-PRTS", .Range("A1:A" & AudLastCol), 0)).Value
ud = .Cells(l, Application.Match("Deployed (Unassigned)", .Range("A1:A" & AudLastCol), 0)).Value
du19 = d19 + ud
du8 = d8 + ud
du25 = d25 + ud
If aPRTS = bNIMS Then
If (p19 = d19 Or p19 = du19) And (p8 = d8 Or p8 = du8) And (p25 = d25 Or p25 = du25) Then
.Cells(l, AudLastCol + 1).Value = "TRUE"
.Cells(l, AudLastCol + 3).Value = "No Action required."
Else
.Cells(l, AudLastCol + 1).Value = "FALSE"
.Cells(l, AudLastCol + 3).Value = "Band wise Carrier Mismatch."
End If
End If
Next l
自 OP 的代码更改后进行编辑 (...)
你必须改变:
d19 = .Cells(l, Application.Match("Deployed(1.9)", .Range("A1:A" & AudLastCol), 0)).Value
至:
d19 = .Cells(l, Application.Match("Deployed(1.9)", .Rows(1).Resize(,AudLastCol), 0)).Value
实际在第 1 行搜索到 AudLastCol 列而不是从第 1 列搜索到 AudLastCol 行
与其他代码行相同