Function ExtractTax(totalAmount As Double, taxRate As Double, roundUp As Boolean) As Double ' 税抜き金額を計算します Dim taxExcludedAmount As Double taxExcludedAmount = totalAmount / (1 + taxRate / 100) ' 税金額を計算します Dim taxAmount As Double taxAmount = totalAmount - taxExcludedAmount ' 第三引数に基づいて上に切り上げるか下に切り捨てるかを決定します If roundUp Then ExtractTax = Application.WorksheetFunction.RoundUp(taxAmount, 0) Else ExtractTax = Application.WorksheetFunction.RoundDown(taxAmount, 0) End If End Function