此代码中是否存在任何语法错误?

时间:2019-08-25 13:27:51

标签: excel vba

我的目的是从一个工作表(表1)中复制一些数据,并将其(仅值)粘贴到另一工作表中(缺少数字-选定的部分)。我已经编写了代码,但显示错误-“下标超出范围”。可能是我犯了任何语法错误,或者可能是我缺少了VBA的某些功能。请帮助我。

我已经编写了代码。如下所示。

Sub Check_123()
Dim i As Integer, j As Integer, i_max As Integer, j_max As Integer
i = 0
j = 0
i_max = 10 'Max value of i that can be entered
j_max = 31 'Range of columns - 6 Num to 36 Num
For i = 1 To i_max Step 1
    Worksheets("Missing Num - Selected Part").Range("C5").Value = Worksheets("Missing Num - Selected Part").Cells(i + 3, 5).Value   
        For j = 1 To j_max Step 1
            Worksheets("Missing Num - Selected Part").Cells(3 + i, 5 + j).Value = Worksheets("Sheet 1").Cells(38, 3 + j).Value
            'RHS is original strip from which data has to be extracted & LHS where data has to be entered
        Next j
Next i


End Sub

1 个答案:

答案 0 :(得分:0)

对于行和列,Excel单元格索引均以1而不是0开头。例如,使用C2访问单元格Cells(2,3)。因此,请确保您的ij的初始值为1