循环程序的问题将格式设置为一般select单元格

我正在尝试将工作簿中多个工作表中的所有单元格的格式设置为一般格式,以便我的图表随着显示的正确数据进行更新。 这在一个单一的活动页面上运行良好,但我不能得到它正确的循环,因为它也很慢。

Sub SettingFormatToGeneral() Dim works As Worksheet For Each works In ActiveWorkbook.Worksheets Range("A:Q").Select 'specify the range which suits your purpose With Selection Selection.NumberFormat = "General" .Value = .Value End With Next works End Sub 

使用UsedRange限制您的数据集。

  Sub SettingFormatToGeneral() Dim works As Worksheet For Each works In ActiveWorkbook.Worksheets 'specify the range which suits your purpose With works.UsedRange.Resize(, 17) '/ Only refer the used range and columns A:Q. .NumberFormat = "General" .Value = .Value End With Next works End Sub