User defined function with variable inputs? How do I do it

johnryanday

New Member
Joined
Nov 14, 2007
Messages
10
I want to build something like this....

function getdb(a,b,c,d,e,f........x)
getdb = a & "," & b & "," & c &....& x
end function

where x is the total number of variables.

So if in excel, I run getdb (a,b) that it will know that the funciton has only 2 variables but if i run getdb(a,b,c,d,e,f,g,h,i,j) that it knows.

I am trying to avoid getdb(a,b,,,,,,,,,,,,,,,,,,,) as I bet the user will not know how many ","s to use

any help would be appreciated

Ryan
 
Now that it has been a while, I want to build the function to have both individual and arrays. i.e. where in the past it was ......

getdb(A,B,C,D,E,F)

I want

getdb(A,B,C:F,G,H:M)

any thoughts on what changes I need to make to my previous code of...
************************************************
Function getdb(ParamArray myval() As Variant)

For i = LBound(myval) To UBound(myval)
x = x & myval(i) & ","
If i = UBound(myval) Then
x = Left(x, Len(x) - 1)
End If
Next i

getdb = Join(myval, ",")

End Function
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Figured it out myself. For anyone who cares......

Function xgetdb(ParamArray myval() As Variant)

For i = LBound(myval) To UBound(myval)

tester = myval(i).Address
coloncount = Len(tester) - Len(Application.WorksheetFunction.Substitute(Application.WorksheetFunction.Substitute(tester, ":", ""), ":", ""))
If coloncount > 0 Then
myval(i) = myval(i).Address
Else
myval(i) = myval(i)
End If

coloncount = 0

Next i

xgetdb = Join(myval, ",")
End Function
 
Upvote 0

Forum statistics

Threads
1,216,030
Messages
6,128,405
Members
449,448
Latest member
Andrew Slatter

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top