我只需使用vba代码更改工作表的格式,并且文件变得非常大并且增加了大约200 MB。如果我使用excel界面来做这件事,那么就不会发生这种情况,但我想使用代码。更改excel的格式将文件转化为疯狂的大小
Function ReturnName(ByVal num As Integer) As String
ReturnName = Split(Cells(, num).Address, "$")(1)
End Function
lcol = ws1.Cells(1, ws1.Columns.Count).End(xlToLeft).Column
For i = 1 To lcol
If (ws1.Cells(4, i) = "Date") Then
ws1.Range(ReturnName(i) & "5" & ":" & ReturnName(i) & "1000").NumberFormat = "yyyy-mm-dd"
Else
ws1.Range(ReturnName(i) & "5" & ":" & ReturnName(i) & "1000").NumberFormat = "0"
End If
Next i
是因为你的情况可以格式化整个柱上进行(S),而不是在列996个细胞是否可以接受?这应该会产生巨大的差异...意味着更小的文件大小。 –
您只向我们展示了部分代码,因此我必须问是否有可能将错误的值放入流氓'最后一个单元格'(如'Z1048576')中。 “Ctrl + End”在工作表上将你带到哪里? 'Debug.Print ws1.Cells.SpecialCells(xlLastCell).Address(0,0)'报告是什么? – Jeeped