【问题标题】:VBA to loop through all worksheets and clear cell contentsVBA循环遍历所有工作表并清除单元格内容
【发布时间】:2019-02-28 15:46:49
【问题描述】:

我有下面的代码,但我不断收到运行时错误 438,有人可以帮我调试吗?谢谢!

Sub my sub ()

Dim wb As Workbook
Set wb = Workbooks.Open(link to file)

Dim ws As Worksheet

For Each ws In wb
    ws.Cells.ClearContents
Next

End Sub

【问题讨论】:

  • For Each ws In wb.Worksheets.

标签: excel vba loops


【解决方案1】:

试试:

Option Explicit

Sub Test()

Dim ws As Worksheet
'Loop all sheet in the workbook
For Each ws In ThisWorkbook.Worksheets
    'Clear the used range of the sheet
    ws.UsedRange.Clear 'or .ClearContents
Next ws

End Sub

【讨论】:

    猜你喜欢
    • 2012-03-25
    • 2023-03-23
    • 1970-01-01
    • 2018-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多