需要宏才能在特定工作表上运行,而不是在活动工作表上运行

时间:2014-08-12 16:39:06

标签: excel vba excel-vba

我有这个宏,它需要在“客户列表”表上运行,而不是在活动表上运行。这是一系列宏的一部分,所以我不能点击表格。感谢。

Sub Check()
    Dim dat As Variant
    Dim rng As Range
    Dim i As Long

    Set rng = Range("D2:D100")
    dat = rng
    For i = LBound(dat, 1) To UBound(dat, 1)
        If dat(i, 1) <> "" Then
            rng(i, -2).Value = "X"
        End If
    Next
End Sub

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

Sub Check()
    Dim dat As Variant
    Dim rng As Range
    Dim i As Long

    Set rng = Sheets("Customer List").Range("D2:D100")
    dat = rng.Value
    For i = LBound(dat, 1) To UBound(dat, 1)
        If dat(i, 1) <> "" Then
            rng(i, -2).Value = "X"
        End If
    Next
End Sub