VBA宏指向工作表 - 完全合格?

时间:2017-02-24 14:40:14

标签: vba excel-vba excel

如果我的活动工作表是“管道 - 承保数据D”而不是来自任何其他工作表,则此宏有效。

我假设是因为我错误地认定了什么?

在调整代码以便在不选择/激活相关工作表的情况下运行的任何帮助都将非常感激!

Dim pipe As Integer
With Sheets("Pipeline - Underwriting Data D")
    pipe = .Range("A" & .Rows.Count).End(xlUp).Row - 1
End With

With Sheets("Pipeline - Underwriting Data D")
    Dim Containword As String
    Dim rng As Range
    Set rng = Range(Cells(2, 14), Cells(pipe + 1, 14))
    Containword = "Outside Counsel"
    For Each cell In rng.Cells
        If cell.find(Containword) Is Nothing Then cell.Clear
    Next cell
End With

1 个答案:

答案 0 :(得分:1)

你错过了“。”为你的“With”块指向正确的范围。见下文:

Dim pipe As Integer
With Sheets("Pipeline - Underwriting Data D")
    pipe = .Range("A" & .Rows.Count).End(xlUp).Row - 1
End With

With Sheets("Pipeline - Underwriting Data D")
    Dim Containword As String
    Dim rng As Range
    Set rng = .Range(.Cells(2, 14), .Cells(pipe + 1, 14))
    Containword = "Outside Counsel"
    For Each cell In rng.Cells
        If cell.find(Containword) Is Nothing Then cell.Clear
    Next cell
End With