「Excel VBA」WorksheetFunction.RoundUpメソッドで数値を切り上げるサンプル

書式
WorksheetFunction.RoundUp(引数1、引数2)
引数1 数値: 切り上げの対象となる実数値を指定します。
引数2 桁数: 数値を切り上げた結果の桁数を指定します。
RoundUp は、 常に 数値を切り上げない限り、Round と同様に動作します。
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Sub funA()
Dim cftA As Double
cftA = 4.5
Debug.Print WorksheetFunction.RoundUp(cftA, 0)
Debug.Print "************"
Dim cftB As Double
cftB = 5.27
Debug.Print WorksheetFunction.RoundUp(cftB, 0)
Debug.Print WorksheetFunction.RoundUp(cftB, 1)
Debug.Print "------------"
Dim cftC As Double
cftC = 7.76
Debug.Print WorksheetFunction.RoundUp(cftC, 0)
Debug.Print WorksheetFunction.RoundUp(cftC, 1)
End Sub
Sub funA() Dim cftA As Double cftA = 4.5 Debug.Print WorksheetFunction.RoundUp(cftA, 0) Debug.Print "************" Dim cftB As Double cftB = 5.27 Debug.Print WorksheetFunction.RoundUp(cftB, 0) Debug.Print WorksheetFunction.RoundUp(cftB, 1) Debug.Print "------------" Dim cftC As Double cftC = 7.76 Debug.Print WorksheetFunction.RoundUp(cftC, 0) Debug.Print WorksheetFunction.RoundUp(cftC, 1) End Sub
Sub funA()

    Dim cftA As Double
    cftA = 4.5
    Debug.Print WorksheetFunction.RoundUp(cftA, 0)
    
    Debug.Print "************"
    Dim cftB As Double
    cftB = 5.27
    Debug.Print WorksheetFunction.RoundUp(cftB, 0)
    Debug.Print WorksheetFunction.RoundUp(cftB, 1)
    
    Debug.Print "------------"
    Dim cftC As Double
    cftC = 7.76
    Debug.Print WorksheetFunction.RoundUp(cftC, 0)
    Debug.Print WorksheetFunction.RoundUp(cftC, 1)

End Sub

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
5
************
6
5.3
------------
8
7.8
5 ************ 6 5.3 ------------ 8 7.8
 5 
************
 6 
 5.3 
------------
 8 
 7.8

 

Excel VBA

Posted by arkgame