|
请教代码,结果为0却是9.09494701772928E-13,如何处理,谢谢
Option Explicit
Sub a()
Application.ScreenUpdating = False
[a1].CurrentRegion.Clear
Dim d As Object
Set d = CreateObject("Scripting.Dictionary")
Dim arr, i&, s$
arr = Sheets("SAP").[a1].CurrentRegion
For i = 2 To UBound(arr) '不含标题行
s = arr(i, 3) '条件
d(s) = d(s) + Val(arr(i, 18)) '求和列,指定
Next
With [a2]
.Resize(d.Count, 2) = Application.Transpose(Array(d.Keys, d.Items))
.Offset(-1).Resize(1, 2) = Array("单据编号", "SAP表-税金")
End With
d.RemoveAll
arr = Sheets("交票").[a3].CurrentRegion
For i = 2 To UBound(arr) '含标题行
s = arr(i, 2) '条件
d(s) = d(s) + Val(arr(i, 6)) '求和列,指定
Next
[c1] = "交票表-税金"
[d1] = "差异"
Dim brr
brr = [a1].CurrentRegion
For i = 2 To UBound(brr)
s = brr(i, 1) '条件,与上面一致
If d.Exists(s) Then
brr(i, 3) = d(s)
End If
brr(i, 4) = brr(i, 2) - brr(i, 3) 此代码结果如何保留为数值,两位小数,因结果可能是9.09494701772928E-13
Next
[a1].Resize(UBound(brr), UBound(brr, 2)) = brr
Set d = Nothing
With [a1]
.CurrentRegion.Borders.LineStyle = 1 '加边框
.CurrentRegion.EntireColumn.AutoFit '调整列宽
.CurrentRegion.HorizontalAlignment = xlCenter '水平居中
.CurrentRegion.VerticalAlignment = xlCenter '垂直居中
.Resize(1, UBound(brr, 2)).Font.Bold = True '加粗
.Resize(1, UBound(brr, 2)).Interior.Color = 12692612 '颜色
End With
Application.ScreenUpdating = True
MsgBox "统计完成"
End Sub
|
|