Someone may post prettier code, but an option:
Sub mscott123()
Dim ws As Worksheet
Dim i As Integer, j As Integer, k As Integer
Dim myArr
Dim mycell As Range
Set ws = ThisWorkbook.Sheets("Sheet1")
myArr = ws.Range("B8:E10")
'clear the destination columns... since the loop number is in the row above the "table" but the table may be blank, we add 3 rows
lr = ws.Range("L" & Rows.Count).End(xlUp).Row + 3
ws.Range("L7:O" & lr).Clear
Select Case UCase(ws.Range("B6").Value)
Case "CUMULATIVE INCREMENTAL"
For i = 1 To ws.Range("F6").Value
Set mycell = ws.Range("L" & i + 6).Offset((i - 1) * 3)
mycell.NumberFormat = "@"
mycell.Value = i & "."
For j = LBound(myArr, 1) To UBound(myArr, 1)
For k = LBound(myArr, 2) To UBound(myArr, 2)
If myArr(j, k) <= i Then mycell.Offset(j, k - 1).Value = "a"
Next k
Next j
With ws.Range(mycell.Offset(1, 0), mycell.Offset(3, 3))
.Borders.LineStyle = xlContinuous
.Borders.Weight = xlThin
.Font.Name = "Marlett"
End With
Next i
Case "NON-CUMULATIVE INCREMENTAL"
For i = 1 To ws.Range("F6").Value
Set mycell = ws.Range("L" & i + 6).Offset((i - 1) * 3)
mycell.NumberFormat = "@"
mycell.Value = i & "."
For j = LBound(myArr, 1) To UBound(myArr, 1)
For k = LBound(myArr, 2) To UBound(myArr, 2)
If myArr(j, k) = i Then mycell.Offset(j, k - 1).Value = "a"
Next k
Next j
With ws.Range(mycell.Offset(1, 0), mycell.Offset(3, 3))
.Borders.LineStyle = xlContinuous
.Borders.Weight = xlThin
.Font.Name = "Marlett"
End With
Next i
End Select
End Sub
It could be consolidated so that the case statement is inside all the loops and only applies to the "If myArr(j, k)..." line, which is more compact, but would execute the select a lot more times and in theory is less efficient.
Bookmarks