A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Wayne,
My above code but now with the headers of each column as part of the groupnames:
Dim sh As Worksheet
Dim rng As Range
Dim rngT As Range
Dim i, k As Long
Dim lngGroup, lngGroups As Long, lngGap As Long
Dim varGroupNames(50) As Variant
Application.ScreenUpdating = False
lngGroup = 15 'count of items in a group
lngGroups = 50 'count of columns
lngGap = 2 'count of rows to be inserted between groups
Set sh = ActiveSheet
'fill this array with groupname you want to use, at least
'lngGroups names in this array
' varGroupNames = Array("Group", "List", "Some", "Other")
'Now instead use the header from each column as start of the groupnames
For i = 0 To 49
varGroupNames(i) = sh.Cells(1, i + 1).Value
Next
Set rng = sh.Range("A" & 2).Resize(lngGap)
Set rngT = rng
i = 0
Do Until rng.Resize(1) = ""
Set rngT = Union(rngT, rng)
i = i + 1
Set rng = sh.Range("A" & i * lngGroup + 2).Resize(lngGap)
Loop
rngT.EntireRow.Insert
Set rngT = rngT.Offset(-1)
For i = 1 To rngT.Areas.Count
With rngT.Areas(i).Resize(1)
For k = 0 To lngGroups - 1
If .Offset(1, k) <> "" Then
If varGroupNames(k) <> "" Then
.Offset(0, k) = varGroupNames(k) & " " & Format(i, "0000")
End If
End If
Next
With .Resize(1, lngGroups)
.Font.Bold = True
.Font.Color = RGB(80, 80, 255)
End With
End With
Next
Application.ScreenUpdating = True
End Sub
Part of the result:
Jan