我會開始說我有一個星期前開始教自己的VBA,所以我可能不會問正確的問題,但...在Word VBA中增加0.05的小數點
我是試圖在Word VBA中編寫一個循環,該循環將增加從書籤檢索的文本中部分計算的數字。我希望它湊到最接近的0.05,所以.87變成0.90和0.21變成0.25。
我寫模塊如下:
A = ActiveDocument.Bookmarks("SRebateIncome").Range.Text
B = ActiveDocument.Bookmarks("RebateDefault").Range.Text
C = ((A - 6000) * 0.15)
D = B - C
E = B + D
F = (18200 + ((445 + E)/0.19)) + 1
G = (0.19 * 18200) + 445 + E + (37000 * (0.015 + 0.325 - 0.19))
H = (G/(0.015 + 0.325)) + 1
I = ActiveDocument.Bookmarks("TRebateIncome").Range.Text
If F < 37000 = True Then
J = (0.125 * (I - F))
Else
J = (0.125 * (I - H))
End If
K = E - J
K = Format(Round(K, 2), "###,##0.00")
'round K up to the nearest .00 or .05
If K <> "###,###.#0" = False or K <> "###,###.#5") = False Then
Do
K = K + 0.01
Loop Until K = "###,###.#0" = True or K <> "###,###.#5") = True
End If
Set RebateOutput = ActiveDocument.Bookmarks("RebateOutput").Range
RebateOutput.Text = K
現在假設用於書籤「SRebateIncome」,「RebateDefault」和「TRebateIncome」的值輸入是10175,1602和43046分別我期望的輸出爲1460.80,但是「K」返回爲1460.78。
在這個階段,我不知道在Word中使用Excel的任何內容(除了複製/粘貼到文檔的電子表格,我不想這樣做)。
任何幫助,將不勝感激
謝謝!
乘以20,舍入到最接近的整數,然後除以20。 –