这段代码有什么问题? Excel VBA

时间:2018-03-20 11:45:48

标签: excel vba for-loop

我不知道这段代码有什么问题。错误1004不断弹出。我是VBA的新手,所以也许我在嵌套for循环中遗漏了一些东西。这个子目的的目的是删除一个单元格离开另一个单元格,如是 - 不 - 不 - 是 - 否 - 否......

Sub hola7()
    Dim i As Integer
Dim j As Integer
For j = columnn To column + userinput
    For i = column To column + userinput Step 3
        If j <> i Then
            Cells(row, j).Selection
            Selection.ClearContents
        End If
    Next
Next
End Sub

1 个答案:

答案 0 :(得分:1)

使用。选择,而不是。选择。

Sub hola7()
    Dim i As LONG, j As LONG
    For j = column To column + userinput
        For i = column To column + userinput Step 3
            If j <> i Then
                Cells(row, j).SELECT
                Selection.ClearContents
            End If
        Next
    Next
END SUB

我假设您已经为列,行和用户输入设置了灰色并分配了值。