对象的方法范围_worksheet失败错误

时间:2016-10-01 17:36:35

标签: excel-vba vba excel

编译此代码时,我总是遇到此错误:

Private Sub CommandButton1_Click()

Dim rng As String
Dim x As String
Dim i As Integer
Dim ws As Worksheet

Set ws = ActiveWorkbook.Worksheets("Budget")
x = range("A20").Value

For i = 2 To 20
    If Cells(i, 1) = x Then
        rng = ws.range(ws.Cells(i, 17)).Value
    End If
Next I
MsgBox rng

Worksheets("Shortage").Activate
Worksheets("Shortage").range(rng).Activate

End Sub

非常感谢。

0 个答案:

没有答案