VBE313
Well-known Member
- Joined
- Mar 22, 2019
- Messages
- 686
- Office Version
- 365
- Platform
- Windows
In the following function, I want to get every column that says "Y" and sum everything until the next "Y". My function works properly. However, What if column B was not next to column A? How can I get the range with two columns that are not connected?
Here is an example of what I need to accomplish (i know this doesn't work)
VBA Code:
Function getY(rng As Range)
Dim i As Integer, j As Integer, n As Integer
Dim temp As Integer, A(), ret()
n = rng.Rows.Count
ReDim ret(1 To n, 0)
A = rng
For j = 1 To n
If A(j, 2) = "Y" Then
ret(j, 0) = A(j, 1)
i = 0
Else
i = i + 1
ret(j - i, 0) = ret(j - i, 0) + A(j, 1)
End If
Next j
getY = ret
End Function
Here is an example of what I need to accomplish (i know this doesn't work)