Excel宏可在除一张纸之外的所有纸上运行

时间:2019-03-26 12:45:10

标签: excel vba

下面的Excel宏在多个预定的工作表上运行并格式化它们。我正在尝试对其进行修改,以使其格式化工作簿中除一张纸之外的所有工作表。

所有表格,无论名称如何,都应格式化,除了“查找”表格。

下面列出的代码已缩短为仅显示一张纸,它对另外10张纸做同样的事情,但是我不想将所有内容都放在这里。谢谢。

Sub Formatting()


Application.ScreenUpdating = False


Sheets("Products").Select
Columns("F:W").Select
Selection.EntireColumn.Hidden = True
Range("X1").Select
Selection = "Product #"
Range("X1").Font.Bold = True


With Sheets("Products")
    .Range("X2:X" & .Cells(.Rows.Count, "A").End(xlUp).row).Formula = "=IF(ISNA(VLOOKUP(S2,Lookup!C:D,2,FALSE)),"""",VLOOKUP(S2,Lookup!C:D,2,FALSE))"
    .Range("Z2:Z" & .Cells(.Rows.Count, "A").End(xlUp).row).Formula = "=IF(ISNA(VLOOKUP(S2,Lookup!C:D,2,FALSE)),"""",VLOOKUP(S2,Lookup!C:D,2,FALSE))"
    .Range("AC2:AC" & .Cells(.Rows.Count, "A").End(xlUp).row).Formula = "=IF(Z2="""","""",E2)"
End With


Range("A1:X50").Select
ActiveWorkbook.Worksheets("Products").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Products").Sort.SortFields.Add _
    Key:=Range("X2:X50"), SortOn:=xlSortOnValues, Order:=xlDescending, _
    DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Products").Sort
    .SetRange Range("A1:X50")
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With
Columns("X:X").ColumnWidth = 9

Application.ScreenUpdating = True

End Sub

1 个答案:

答案 0 :(得分:2)

浏览工作表是关键:

{{ groups['test-node'].1 }}