![]()
Sub X() Dim header As Range Dim data As Range Dim output As Range Dim rowIndex As Long Dim colIndex As Long Dim letterIndex As Long Dim letter As String Dim tally As Long Dim total As Long Dim drawData As Range Dim drawDataRow As Range Dim numberData As Range Dim xpos As Variant Set drawData = Range("A6").CurrentRegion Set header = Range("I4:AU4") ' assume fixed location Set numberData = Range("I5:AU5") ' assume fixed location Set data = Range("I6:AU6") Set output = Range("AW6") For Each drawDataRow In drawData.Rows For colIndex = 1 To drawDataRow.Columns.Count xpos = Application.Match(drawDataRow.Cells(1, colIndex), numberData, 0) data.Cells(1, xpos) = "X" Next total = 0 For letterIndex = 1 To 4 tally = 0 letter = Chr(64 + letterIndex) For colIndex = 1 To data.Columns.Count If header.Cells(1, colIndex) = letter Then If Len(data.Cells(1, colIndex)) > 0 Then tally = tally + 1 End If End If Next output = tally total = total + tally Set output = output.Offset(0, 1) Next output.Offset(0, 1) = total Set output = output.Offset(1, -4) ' move reference down a row Set data = data.Offset(1, 0) ' move reference down a row Next End Sub
Bookmarks