VBA 消費税計算
エクセルにて消費税を研鑽させるVBAを書いてみました。
----
Private Sub Run_Click()
Dim hontai As Currency
Dim tax As Currency
Dim all As Currency
'消費税率
'******************************
Const Duty As Double = 0.05
'******************************
'初期値設定
'------------------------------
hontai = input1.Value
tax = Input2.Value
all = Input3.Value
'計算
'------------------------------
If hontai <> 0 Then
'販売価格が分かるケース
tax = hontai * Duty
all = hontai * (1 + Duty)
ElseIf tax <> 0 Then
'消費税が分かるケース
hontai = tax / Duty
all = (tax / Duty) + tax
ElseIf all <> 0 Then
'税込価格がが分かるケース
hontai = all / (1 + Duty)
tax = (all / (1 + Duty)) * Duty
End If
'計算結果出力
'--------------------------------
hontai = Application.RoundUp(hontai, 0) '小数第一位を切り上げ
tax = Application.RoundDown(tax, 0) '小数第一位を切り捨て
all = Application.RoundUp(all, 0) '小数第一位を切り上げ
input1.Value = Format(hontai, "###,###") 'コンマ挿入
Input2.Value = Format(tax, "###,###") 'コンマ挿入
Input3.Value = Format(all, "###,###") 'コンマ挿入
End Sub
----
「VBA」カテゴリの記事
- エクセル VBA 範囲指定(2009.10.16)
- エクセル VBA プリンタを指定して印刷(2009.04.24)
- エクセル VBA ピポットテーブルを作成(2009.04.17)
- エクセル VBA ファイル・フォルダの存在確認(2009.04.16)
- Excel VBA Tips (1)(2009.04.15)
The comments to this entry are closed.
Comments