為什麼這篇vba不等於鄉民發文收入到精華區:因為在vba不等於這個討論話題中,有許多相關的文章在討論,這篇最有參考價值!作者yimean (溫柔殺手)看板Office標題[算表] VBA計算後溢位問題時間Tue Jul ...
軟體:Excel
版本:Office 365
各位版上的神人早上好。
我撰寫了一個簡單的用料計算程式。
執行的時候會卡在
PrPS = Round(1220 * 2440 * MP * Density * Thick / 10 ^ 6, 2)
錯誤資訊是"溢位"
我有嘗試把變數宣告為Variant或著甚至不宣告都出現這個問題
在儲存格中打公式不會有問題,但是在VBA中就會有。
在這應用情境中
MP=170, Density=2.7, Thick=2, length=133.5, width=133.5, buffer=2
煩請高手協助,感恩。
--------我是Code--------
Sub Non_circule_material_calculate(length As Single, width As Single, buffer
As Single, MP As Single, Density As Single, Thick As Single)
Dim R_L, R_W As Single 'R_L stands for remainder of length
Dim PsPS As Integer 'PsPP stands for pice per sheet
Dim PrPS As Variant 'PrPS stands for price per sheet
Dim PrPP As Single 'PrPP stands for price per pice
Dim CoilP As Variant 'Coil price
PrPS = Round(1220 * 2440 * MP * Density * Thick / 10 ^ 6, 2)
R_L = (1220 Mod (length + buffer)) * (length + buffer)
R_W = (1220 Mod (width + buffer)) * (width + buffer)
If R_L < R_W Then
PsPP = (1220 \ (length + buffer)) * (2440 \ (width + buffer))
PrPP = PrPS / PsPS
Else
'除卻第一種狀況只有等於與不等於的問題。如果是等於,那麼不論是哪一種排
法其實都沒有問題。
PsPP = (2440 \ (length + buffer)) * (1220 \ (width + buffer))
PrPP = PrPS / PsPS
End If
CoilP = Round((length + buffer) * (width + buffer) * MP * Density * Thick
/ 10 ^ 6, 2)
[D10] = CoilP
[D11] = PrPP
End Sub
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.33.116.8 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Office/M.1594090178.A.A66.html
※ 編輯: yimean (114.33.116.8 臺灣), 07/07/2020 10:50:36