VBA-更改范围变量的行会导致错误1004

时间:2018-10-22 21:57:51

标签: excel vba

伙计们,我不明白为什么这个1004在第一次循环中表现良好,并且每次都没有解释中断,有人可以帮助我吗? 工作表中的所有单元格肯定都不为空。

Private Sub CommandButton1_Click()
    Dim num_pasta As Range
    Dim risco_bruto As Range
    Dim risco_liquido As Range
    Dim data_calculo As Range
    Dim alcada_min As Range
    Dim alcada_max As Range
    Dim alcada_maj As Range
    Dim estrategia_final As Range
    Dim provisao_bruto As Range
    Dim provisao_liquido As Range
    Dim restricao As Range

    Set num_pasta = Sheets("Planilha1").Cells(Rows.Count, "A").End(xlUp)
    Set risco_bruto = num_pasta.Offset(0, 2)
    Set risco_liquido = num_pasta.Offset(0, 4)
    Set data_calculo = num_pasta.Offset(0, 3)
    Set alcada_min = num_pasta.Offset(0, 6)
    Set alcada_max = num_pasta.Offset(0, 7)
    Set alcada_maj = num_pasta.Offset(0, 8)
    Set estrategia_final = num_pasta.Offset(0, 9)
    Set provisao_bruto = num_pasta.Offset(0, 11)
    Set provisao_liquido = num_pasta.Offset(0, 12)
    Set restricao = num_pasta.Offset(0, 13)

    Dim signal As Boolean
    Dim row As Integer

    signal = True
    row = 0
    MsgBox risco_bruto.row

    Do While signal
        'Incrementa a linha'
        row = row + 1        
        If risco_bruto.row - row Like "0" Then
            signal = False
        Else
            MsgBox row
            Set risco_bruto = risco_bruto.Offset(-row, 0)        
        End If
    Loop
End Sub

0 个答案:

没有答案