Jak napisano, twoja funkcja przyjmuje tylko dwa zakresy jako argumenty.
Aby umożliwić stosowanie w funkcji zmiennej liczby zakresów, należy zadeklarować tablicę wariantów ParamArray na liście argumentów. Następnie możesz przetworzyć każdy z zakresów w tablicy po kolei.
Na przykład
Function myAdd(Arg1 As Range, ParamArray Args2() As Variant) As Double
Dim elem As Variant
Dim i As Long
For Each elem In Arg1
myAdd = myAdd + elem.Value
Next elem
For i = LBound(Args2) To UBound(Args2)
For Each elem In Args2(i)
myAdd = myAdd + elem.Value
Next elem
Next i
End Function
Funkcja ta może być następnie wykorzystane w arkuszu, aby dodać wiele zakresów.

Na swojej funkcji, pojawia się pytanie, który z zakresów (lub komórek), które mogą przekazanych do funkcji są „Sesje”, a które „Klienci”.
Najprostszym rozwiązaniem będzie, jeśli zdecydujesz, że pierwszy zakres to Sesje, a kolejne kolejne to Klienci.
Function calculateIt(Sessions As Range, ParamArray Customers() As Variant) As Double
'This function accepts a single Sessions range and one or more Customers
'ranges
Dim i As Long
Dim sessElem As Variant
Dim custElem As Variant
For Each sessElem In Sessions
'do something with sessElem.Value, the value of each
'cell in the single range Sessions
Debug.Print "sessElem: " & sessElem.Value
Next sessElem
'loop through each of the one or more ranges in Customers()
For i = LBound(Customers) To UBound(Customers)
'loop through the cells in the range Customers(i)
For Each custElem In Customers(i)
'do something with custElem.Value, the value of
'each cell in the range Customers(i)
Debug.Print "custElem: " & custElem.Value
Next custElem
Next i
End Function
Jeśli chcesz zawierać dowolną liczbę zakresów Sesje i dowolną liczbę Klientów wahać, a potem trzeba będzie to argument, który powie funkcję tak, że można go oddzielić sesji waha się od wahają klientów.
Ten argument może zostać ustawiony jako pierwszy, numeryczny, argument funkcji, która określałaby, ile z następujących argumentów to zakresy Sesji, a pozostałe argumenty niejawnie są zakresami klientów. podpis danej funkcji będzie wówczas:
Function calculateIt(numOfSessionRanges, ParamAray Args() As Variant)
Albo może to być „straż” Argument, że oddziela sesji waha się od zakresów klientów. Następnie twój kod będzie musiał przetestować każdy argument, aby sprawdzić, czy to był strażnik. Funkcja będzie wyglądać następująco:
Function calculateIt(ParamArray Args() As Variant)
Może o czymś połączeń takich jak:
calculateIt(sessRange1,sessRange2,...,"|",custRange1,custRange2,...)
Logika program może następnie być wzdłuż linii:
Function calculateIt(ParamArray Args() As Variant) As Double
...
'loop through Args
IsSessionArg = True
For i = lbound(Args) to UBound(Args)
'only need to check for the type of the argument
If TypeName(Args(i)) = "String" Then
IsSessionArg = False
ElseIf IsSessionArg Then
'process Args(i) as Session range
Else
'process Args(i) as Customer range
End if
Next i
calculateIt = <somevalue>
End Function
Jako alternatywę dla ParamArray może można przypisać zdefiniowaną nazwę do swojego zbioru komórek rozłącznych i podać nazwę. –