我对VB很陌生并且有一个可能很简单的问题 - 我需要浏览工作簿中的所有工作表并删除所有图表(散布在周围),选择包含数据的最后一行,向后移动并删除空行。我尝试了从StackOverflow甚至从MS网站组装的东西,但似乎没有任何效果。
Sub DeleteChartsRowsAllSheets()
Dim Ws As Worksheet, chtObj As ChartObject, i As Long
For Each Ws In ThisWorkbook.Worksheets
For Each chtObj In Ws.ChartObjects
chtObj.Delete
Next
'We turn off calculation and screenupdating to speed up the macro.
With Application
'Turn off screen updating and calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
For i = Selection.Rows.Count To 1 Step -1
If WorksheetFunction.CountA(Selection.Rows(i)) = 0 Then
Selection.Rows(i).EntireRow.Delete
End If
Next i
'Turn screen updating and calculation back on
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
Next Ws
End Sub
任何提示? :)
答案 0 :(得分:0)
在嵌套循环中将ActiveSheet.ChartObjects
替换为ws.ChartObjects
。
您目前只删除ActiveSheet
上的图表。