I was stoked to find about VSTACK and HSTACK formulas, because I could trim down some huge formulas, by merging multiple named ranges with VSTACK, and then using index to find a sum in a specified column, using a formula like:
=SUM(INDEX(vStack(VBA_REG_NIS1,VBA_REG_NIS2,VBA_REG_NIS3),,COLUMN()-@COLUMN(VBA_REG_NIS1)+1))
Than I was dissapointed to find that not all computers in my company have the new formula, so I was thinking maybe I can replicate the functionality in VBA.
I tried using the formula below, but when I applied the sum(index(vStack_clone
that I mentioned earlier, I noticed that I'm only getting the total from the first named range, as if the Union actually does horizontal stacking.
Function vStack_clone(ParamArray ranges() As Variant) As Range
Dim I As Long
For I = LBound(ranges) To UBound(ranges)
If I = LBound(ranges) Then
Set vStack_clone = ranges(I)
Else
Set vStack_clone = Union(vStack_clone, ranges(I))
End If
Next
End Function
Can anyone help me clone the VSTACK formula, maybe tell me what I did wrong?