I have cells D11 through H11 merged, D20 through H20 merged, and D25 through H25 merged. We will call the merged rows sections. So D11 through H11 is section 1, D20 through H20 is section 2, etc. The number of rows between the merged sections can vary.
I'm trying to create a vba that can create the vertical range of the cells between sections. So for example, the vertical range between section 1 and 2 would H12 to H19, and the range between section 2 and 3 would be H21 to H24.
Any ideas?
I'm currently trying create an array with 1s and 2s (2s mean there is a merged cell) and then counting the 1s to try to create a range. I don't know if this will work or if there is an easier way to do this.
Sub newGroup()
Dim LastRow As Integer
Dim i As Long
Dim arr() 'This is an array definition
i = 0
LastRow = Cells(Rows.Count, "H").End(xlUp).Row
For i = 12 To LastRow + 1
If Cells(i, 8).MergeCells = True Then
ReDim Preserve arr(1 To i)
arr(i) = 2
Else: arr(i) = 1
End If
Next
End Sub