[英]Excel VBA will not loop through worksheets (Exclude Worksheet)
The macro appears to loops through all of the worksheets fine now. 宏似乎现在循环遍历所有工作表。 However, is there a way that I can make it so the macro does not get applied to a specific worksheet in my workbook, but does get applied to all other worksheets?
但是,是否有一种方法可以实现,以便宏不会应用于我的工作簿中的特定工作表,但是它是否适用于所有其他工作表?
Sub FormatSheet()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
Columns("A:J").Select
Selection.AutoFilter
Columns("A:J").EntireColumn.AutoFit
With Selection
.HorizontalAlignment = xlCenter
End With
With ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
ActiveWindow.FreezePanes = True
Next ws
End Sub
I created a dataset to test this out and found that the code worked just fine. 我创建了一个数据集来测试它,发现代码运行得很好。 So it must be something related to your specific data/worksheets.
因此,它必须与您的特定数据/工作表相关。 I would see if 2 sheets works, or try making a smaller sample on another workbook and see if it works.
我会看到2张是否有效,或者尝试在另一张工作簿上制作一个较小的样本,看看它是否有效。 Sorry I'm not more helpful.
对不起,我没有更多的帮助。
Consider this approach. 考虑这种方法。
Option Explicit
Sub test()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Sheet1" Then
With ws.UsedRange
.Resize(.Rows.Count-1).Offset(1, 0).ClearContents
End With
End If
Next ws
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.