【发布时间】:2016-01-23 09:11:58
【问题描述】:
要在 AP 列中分配 xx,我必须检查一些必须在分配 xx 之前填写的字段
我试图将一些列分配给一个变量,我对该变量进行了控制,但它似乎不起作用
我在这一行遇到了错误
Set MaPlage = Columns("A:R" & "W:E").Rows(i)
这是我的代码:
Sub Decision()
Dim cell As Range
Dim i As Integer
Dim j As Integer
Dim x As Integer
Dim y As Integer
Dim z As Integer
Dim u As Integer
Dim t As Integer
Dim l As Integer
Dim p As Integer
Set MaPlage = Columns("A:R" & "W:E").Rows(i)
For i = 2 To ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row
If CStr(ActiveSheet.Cells(i, 31).Value) = "Completed - Appointment made / Complété - Nomination faite" And (ActiveSheet.MaPlage.Value) = "<>" Then
If CStr(ActiveSheet.Cells(i, 14).Value) = "AEP" _
Or CStr(ActiveSheet.Cells(i, 14).Value) = "CMC_REV" _
Or CStr(ActiveSheet.Cells(i, 14).Value) = "CMC_APT" _
Or CStr(ActiveSheet.Cells(i, 14).Value) = "CS_TPD" _
Or CStr(ActiveSheet.Cells(i, 14).Value) = "DM_ID" Then
ActiveSheet.Cells(i, 42).Value = "XX"
End If
End If
Next i
【问题讨论】:
-
在你设置 maplage i=0 的时候。 i 直到 for 循环才被赋予一个值。也可以使用
Set MaPlage = Range("A" & i & ":R" & i, "W" & i & ":E" & i) -
你遇到了什么错误?
-
@ScottCraner 谢谢你的回答,我试过了,但我还是有同样的错误
-
你给
i一个值了吗。您的行是i = 0并且在 0 处没有行。您需要将语句移动到循环中,或者将大于 1 的值分配给i。 -
我的循环应该从 i=2 开始吧?
For i = 2 To ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row
标签: vba excel error-handling