任何人都可以简化/优化Excel / VBA中的代码吗?

时间:2015-06-23 14:20:01

标签: excel vba excel-vba

这是我从运行宏中获得的一个简单代码,但它需要很长时间才能处理。任何擅长vba的人都可以解决这个问题吗? 感谢。

Sub ClearAll()
    Application.ScreenUpdating = False
    Range("H2:H11").Select
    Selection.ClearContents
    Range("A2:A100").Select
    Selection.ClearContents
    Selection.ClearFormats
    Sheets(2).Select
    Cells.Select
    Selection.ClearContents
    ThisWorkbook.Sheets(3).Rows("2:" & Rows.Count).Delete
    Sheets(1).Select
    Range("A2").Select
    ActiveSheet.UsedRange
    ThisWorkbook.Save
    Application.ScreenUpdating = True
End Sub

1 个答案:

答案 0 :(得分:0)

好一点......

Sub ClearAll()
    Application.ScreenUpdating = False
    Range("H2:H11").ClearContents
    With Range("A2:A100")
        .ClearContents
        .ClearFormats
    End With
    Sheets(2).Cells.ClearContents
    Sheets(3).Rows("2:" & Rows.Count).Delete
    Sheets(1).UsedRange.Select
    ThisWorkbook.Save
    Application.ScreenUpdating = True
End Sub