如何选择范围

时间:2015-10-23 18:19:13

标签: excel vba excel-vba error-handling

要在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

1 个答案:

答案 0 :(得分:0)

结合所有评论,试试这个:

For i = 2 To ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row
    Set maplage = Range("A" & i & ":H" & i & ",J" & i & ":R" & i & ",W" & i & ":Z" & i & ",AA" & i & ":AO" & i)
    If UCase(Left(ActiveSheet.Cells(i, 31).Value), 3) = "COM" _
         And WorksheetFunction.Countif(MaPlage,"") = 0 Then
        Select Case UCase(Left(ActiveSheet.Cells(i, 14).Value), 3)
            Case "AEP", "CMC", "CS_", "DM_"
                ActiveSheet.Cells(i, 42).Value = "XX"
        End Select
    End If
Next i