Sure. I was debating on whether to do that or not.
Sub Summarize()
Dim WS As Worksheet
Dim C As Range
Dim D As Range
Dim FirstAddress As String
Dim A As Long
Dim B As Long
Dim LastRow As Long
Dim CCRow As Long
Dim CCcol As Long
Set WS = Worksheets("Sheet1")
With WS
'Clear the summary range.
.Range("B11:BXY40").ClearContents
'Determine last row of data in the sheet.
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
'Define range from the start of data to the lastrow.
With .Range("A42:A" & LastRow)
'Look for the Phrase 'Cost Code'.
Set C = .Find("Cost Code", , xlValues)
If Not C Is Nothing Then
'We found it.
'Store the first found address for later.
FirstAddress = C.Address
'Start a Do-Loop to find all the phrases.
Do
'Each group is a maximum of 10 by 25 table.
'Iterate the group range.
For A = 1 To 25 'offset of Columns
For B = 1 To 10 'offset of Rows
'Check to make sure the row/column data isn't empty.
If C.Offset(B, A) <> "" Then
'Search the summary table, looking for matching header row.
Set D = WS.Range("A10:A40").Find(C.Offset(B, 0), , xlValues)
'Store the row number.
CCRow = D.Row
Set D = Nothing
'Search the summary table, looking for matching header column.
Set D = WS.Range("B10:BXY10").Find(C.Offset(0, A), , xlValues)
'Store the column number.
CCcol = D.Column
'We now have the address on the table for the data.
WS.Cells(CCRow, CCcol) = C.Offset(B, A)
End If
Next
Next
'Keep looking for more phrases.
Set C = .Find("Cost Code", C, xlValues)
'Stop when it's finished.
Loop While Not C Is Nothing And C.Address <> FirstAddress
End If
End With
End With
End Sub
Bookmarks