This code adds "manually" the values to the sheet, based on the quantity of the values. So if there are less values of some type, it will leave blank spaces. I used the cells on the speardsheet, but you can make operations on the array with the same logic, instead of creating a non contiguous range, you can add values to the array index using For loop Step
Dim ws As Worksheet
Dim one_rng As Range
Dim a1(), a2(), i As Long, ub As Long
Set ws = ThisWorkbook.Worksheets(1)
'Insert the number of values
For n = 1 To 5
If n = 1 Then
n_array = 20 'insert number of valuer for EXPL_1
ElseIf n = 2 Then
n_array = 30 'insert number of valuer for EXPL_2
ElseIf n = 3 Then
n_array = 25 'insert number of valuer for EXPL_3
ElseIf n = 4 Then
n_array = 15 'insert number of valuer for EXPL_4
ElseIf n = 5 Then
n_array = 20 'insert number of valuer for EXPL_5
End If
ReDim a1(1 To 1, 1 To n_array) As Variant
For i = 1 To n_array
a1(1, i) = CStr("EXPL_" & n)
Next i
ub = UBound(a1, 2)
ReDim a2(1 To ub, 1 To 1) 'resize a2 ("right" shape) to match a1
' "flip" the a1 array into a2
For i = 1 To ub
a2(i, 1) = a1(1, i)
Next i
For i = 5 + n To (5 + n) * (n_array - 1) Step 5
If i = (5 + n) Then Set one_rng = ws.Range("B" & n)
Set new_rng = ws.Range("B" & i)
Set one_rng = Union(one_rng, new_rng)
Next i
Debug.Print one_rng.Address 'Verify the Range
one_rng = a2
Next n
If it is desired to delete the blank spaces, some changes can be done.
You can .Autofilter for blank values on the range used (firstrow to last row) and then delete them.
Sub DeleteBlankRows()
Range("B:B").Cells.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub
And after create an array and add the range to the array.
CODE EXPLANATION
Loop 5 times for the five types of EXPL_
For n = 1 To 5
Next n
Insert number of values to create array for each type
If n = 1 Then
n_array = 20 'insert number of valuer for EXPL_1
ElseIf n = 2 Then
n_array = 30 'insert number of valuer for EXPL_2
ElseIf n = 3 Then
n_array = 25 'insert number of valuer for EXPL_3
ElseIf n = 4 Then
n_array = 15 'insert number of valuer for EXPL_4
ElseIf n = 5 Then
n_array = 20 'insert number of valuer for EXPL_5
End If
Create Array
ReDim a1(1 To 1, 1 To n_array) As Variant
For i = 1 To n_array
a1(1, i) = CStr("EXPL_" & n)
Next i
ub = UBound(a1, 2)
ReDim a2(1 To ub, 1 To 1) 'resize a2 ("right" shape) to match a1
' "flip" the a1 array into a2
For i = 1 To ub
a2(i, 1) = a1(1, i)
Next i
Create non contiguous Range skipping 5 rows with the same number of rows as the elements of the array
For i = 5 + n To (5 + n) * (n_array - 1) Step 5
If i = (5 + n) Then Set one_rng = ws.Range("B" & n)
Set new_rng = ws.Range("B" & i)
Set one_rng = Union(one_rng, new_rng)
Next i
Insert array to range
one_rng = a2