I want to print multiple output fields in cells in Excel using a user defined function.
Function CAL(dinero, impuesto)
Dim strText As String
Dim num As Double
num = dinero * 6.8
strText = "Mas impuesto"
Range("A2").Value = strText
Range("B2").Value = num
CAL = dinero + impuesto
CAL = Application.Round(CAL, 2)
End Function
Current result:
Expected result:
You could do that with a Macro.
With a Function, you could output an array. But the cells would be contiguous and could not be specifically within the function.
For example, with your formula in A1
Function CAL(dinero, impuesto)
Dim strText As String
Dim num As Double
Dim calc As Double
Dim v(1 To 2, 1 To 2) As Variant
num = dinero * 6.8
strText = "Mas impuesto"
calc = dinero + impuesto
calc = Application.Round(calc, 2)
v(1, 1) = calc
v(1, 2) = ""
v(2, 1) = strText
v(2, 2) = num
CAL = v
End Function
If your version of Excel does not have dynamic arrays, you can enter the formula as an array across the four cells; or enter four formulas using INDEX
to return each individual component.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.