Quickest way to clear all sheet contents VBA

前端 未结 4 1990
星月不相逢
星月不相逢 2021-02-03 18:05

I have a large sheet that I need to delete all the contents of. When I try to simply clear it without VBA it goes into not responding mode. When using a macro such as:



        
4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-03 18:24

    Try this one:

    Sub clear_sht
      Dim sht As Worksheet
      Set sht = Worksheets(GENERATOR_SHT_NAME)
      col_cnt = sht.UsedRange.Columns.count
      If col_cnt = 0 Then
        col_cnt = 1
      End If
    
      sht.Range(sht.Cells(1, 1), sht.Cells(sht.UsedRange.Rows.count, col_cnt)).Clear
    End Sub
    

提交回复
热议问题