我的代码中的数字格式有问题。
如果我在这个子程序中停止宏并逐步运行它(F8)它运行正常,没有问题。但是,如果它与宏的其余部分作为一个整体运行(不会发布整个事情,因为它非常庞大)它只是不应用数字格式,我似乎无法弄清楚原因。
任何帮助将不胜感激,谢谢!
代码:
Private Sub VolumeIncluded(TWs As Worksheet, MWs2 As Worksheet, MLngth As Double, MFinal As String, TLnght As Double, TFinal As String)
Dim TFtLnght As Double
On Error GoTo NextSheet
TLnght = TWs.Range("$A$" & Rows.Count).End(xlUp).Offset(2).Row
TFinal = "$A$" & TLnght
TWs.Range(TFinal) = "Volume Included"
With TWs.Range(TFinal)
.Interior.Color = 12611584
.Font.ThemeColor = xlThemeColorDark1
.Font.Bold = True
End With
MLngth = MWs2.Range("$H$" & Rows.Count).End(xlUp).Row
MFinal = "$A$16:$H" & MLngth
MWs2.Range(MFinal).Copy
TLnght = TWs.Range("$A$" & Rows.Count).End(xlUp).Offset(1).Row
TFinal = "$A$" & TLnght
TFormat = "$H$" & TLnght
TWs.Range(TFinal).PasteSpecial xlPasteAllUsingSourceTheme
Application.CutCopyMode = False
'----------This piece doesn't work-----------
TFtLnght = TWs.Range("$H$" & Rows.Count).End(xlUp).Row
TFinal = "$H$" & TLnght & ":" & "$H$" & TFtLnght
Range(TFinal).NumberFormat = "#,##0"
NextSheet:
End Sub
答案 0 :(得分:0)
NotificationContentExtension
当您调用Range()时,从您知道的工作表对象引用始终是安全的,因为默认情况下使用活动工作表。