【问题标题】:Can we combine this steps in vba我们可以在vba中结合这些步骤吗
【发布时间】:2022-01-26 05:42:55
【问题描述】:

我已经写了下面的步骤,他们有什么方法可以将这些步骤组合起来使其更小

With Sheets("StockInHandReport")
    .ListObjects("Stock_In_Hand").Range.AutoFilter.ShowAllData
    .ListObjects("Stock_In_Hand").Range.AutoFilter
End With

With Sheets("StockInHandReport").ListObjects("Stock_In_Hand")
    .Range.AutoFilter Field:=WorksheetFunction.Match("Assigned Location", .HeaderRowRange, 0), Criteria1:="<>*Nexa*", Operator:=xlAnd, Criteria2:="<>*Mumbai*"

End With
With Sheets("StockInHandReport")
    .Range("Stock_In_Hand[Model],Stock_In_Hand[SubModel Code],Stock_In_Hand[SubModel]").SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets("DRSR Arena").Range("B6")
    
End With

谢谢

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    您可以像这样嵌套With 语句,以便更轻松地调整代码。

    With Sheets("StockInHandReport")
        With .ListObjects("Stock_In_Hand")
            .Range.AutoFilter.ShowAllData
            .Range.AutoFilter
            .Range.AutoFilter Field:=WorksheetFunction.Match("Assigned Location", .HeaderRowRange, 0), Criteria1:="<>*Nexa*", Operator:=xlAnd, Criteria2:="<>*Mumbai*"
        End With
        .Range("Stock_In_Hand[Model],Stock_In_Hand[SubModel Code],Stock_In_Hand[SubModel]").SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets("DRSR Arena").Range("B6")
    End With
    

    【讨论】:

    • 它确实解决了我的问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-21
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多