简体   繁体   English

此代码有什么问题? Excel VBA

[英]What is wrong with this code? Excel VBA

I have no clue what is wrong with this code. 我不知道这段代码有什么问题。 Error 1004 keeps popping up. 错误1004不断弹出。 I'm new to VBA so maybe I'm missing something on nested for loops. 我是VBA的新手,所以也许我在嵌套的for循环中缺少某些东西。 The purpose of this sub is to delete one cell a leave the other too, as in yes-no-no-yes-no-no... 此子程序的目的是删除一个单元格,同时删除另一个单元格,如是-否-是-否-否...

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

Use .Select, not .Selection. 使用。选择,而不是。选择。

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

I'll assume that you have already dimmed and assigned values to column, row and userinput. 我假设您已经变暗并将值分配给列,行和用户输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM