LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default public function to sum input and return total sum + 10%

Assuming that 2 variables are added, then * 1.1, you can send in a
ParamArray and loop through it. You may have to change the calculation, or
allow odd number of inputs depending on your requirements. Something like:

Private Function igst(taxRate As Single, ParamArray Inputs() As Variant) As
Variant
Dim i As Long
Dim RunTot As Single
'Check if even number of elements in paramarray
If (UBound(Inputs) - LBound(Inputs)) Mod 2 < 1 Then
igst = CVErr(xlErrNum) 'Or other error
Exit Function
End If

For i = LBound(Inputs) To UBound(Inputs) Step 2
RunTot = RunTot + (Inputs(i) + Inputs(i + 1)) * taxRate
Next
igst = RunTot
End Function

Private Sub CommandButton1_Click()
MsgBox igst(1.1, 10, 20, 30, 40, 50, 60, 70, 80)
End Sub

NickHK

"Santa-D" wrote in message
oups.com...
What if the array is larger than 4 variables?

Let's say there is 6 or 8 or 12 variables?

It would be stupid to go

Dim var1, var2, var3, var4.....var99 ?

I guess what I'm trying to do is define an array of values that is
input via the var1,2,3,4 and then return a single string.

i.e.

igst($200,$300,$400,$500) = $1540
at the same time I could do
igst($200) = $220



jseven wrote:
You were getting there. Problem is you have to define each variable.
This will allow you to enter the formula as you wish. Then you have to
return the result to the function by saying "igst = result"

Function igst(var1 As Double, var2 As Double, var3 As Double, var4 As
Double)

igst = ((var1 + var2) * 1.1) + ((var3 + var4) * 1.1)

End Function

Regards,
Jamie




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Public Function Question Carl Excel Worksheet Functions 7 August 31st 06 08:15 PM
Using A Public Function / carl Excel Worksheet Functions 1 April 6th 06 09:13 PM
public function tom mcdonald[_4_] Excel Programming 2 October 10th 05 01:51 PM
Public Function to Return ColorIndex Fries Excel Discussion (Misc queries) 2 July 28th 05 09:23 AM
Public Function Monty Excel Discussion (Misc queries) 9 December 24th 04 06:35 PM


All times are GMT +1. The time now is 03:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"