我有300 excel表格,其中有20列(包括“状态”列)。我想清除所有Excel工作表中与“状态”列相对应的空白值,而不打开每个工作表。目前,我习惯于手动执行此操作,但是这很耗时。请为此提出最佳解决方案。可以使用宏吗?
答案 0 :(得分:0)
实现此目的的一种方法如下,假设您要清除的列是A列,并且清除发生在第2行到最后一行:
Sub foo()
Dim ws As Worksheet
Dim LastRow As Long
Application.ScreenUpdating = False 'disable ScreenUpdating to optimize the processing speed
Application.Calculation = xlCalculationManual 'change to manual to optimize the running of the code
For Each ws In ThisWorkbook.Worksheets 'loop through worksheets
LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
'get the last row with data in each worksheet
ws.Range("A2:A" & LastRow).Clear
'clear the specified range, in this case from Row 2 to Last
Next ws
Application.Calculation = xlCalculationAutomatic 'enable automatic calculations once code has finishe
Application.ScreenUpdating = True 're-set the screen updating
End Sub