[TABLE="class: grid, width: 768"]
<tbody>[TR]
[TD="width: 64, bgcolor: transparent"][/TD]
[TD="width: 64, bgcolor: transparent"]A[/TD]
[TD="width: 64, bgcolor: transparent"]B[/TD]
[TD="width: 64, bgcolor: transparent"]C[/TD]
[TD="width: 64, bgcolor: transparent"]D[/TD]
[TD="width: 64, bgcolor: transparent"]E[/TD]
[TD="width: 64, bgcolor: transparent"]F[/TD]
[TD="width: 64, bgcolor: transparent"]G[/TD]
[TD="width: 64, bgcolor: transparent"]H[/TD]
[TD="width: 64, bgcolor: transparent"]I[/TD]
[TD="width: 64, bgcolor: transparent"]J[/TD]
[TD="width: 64, bgcolor: transparent"]K[/TD]
[TD="width: 64, bgcolor: transparent"]L[/TD]
[/TR]
[TR]
[TD="width: 64, bgcolor: transparent"]1[/TD]
[TD="width: 64, bgcolor: transparent"]
Respondent name
[/TD]
[TD="width: 64, bgcolor: transparent"]
Petition name
[/TD]
[TD="width: 64, bgcolor: transparent"]
var2
[/TD]
[TD="width: 64, bgcolor: transparent"]
var3
[/TD]
[TD="width: 64, bgcolor: transparent"][/TD]
[TD="width: 64, bgcolor: transparent"][/TD]
[TD="width: 64, bgcolor: transparent"]
Person 1
[/TD]
[TD="width: 64, bgcolor: transparent"]
Person 2
[/TD]
[TD="width: 64, bgcolor: transparent"]
Person 3
[/TD]
[TD="width: 64, bgcolor: transparent"]
Person 4
[/TD]
[TD="width: 64, bgcolor: transparent"]
Person 6
[/TD]
[TD="width: 64, bgcolor: transparent"]
Person 17
[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]2[/TD]
[TD="bgcolor: transparent"]
Person 1
[/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"]
Person 1
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent, align: right"]
2
[/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]3[/TD]
[TD="bgcolor: transparent"]
Person 3
[/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"]
Person 2
[/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent, align: right"]
0
[/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent, align: right"]
0
[/TD]
[TD="bgcolor: transparent, align: right"]
0
[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]4[/TD]
[TD="bgcolor: transparent"]
Person 6
[/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"]
Person 3
[/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent, align: right"]
0
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent, align: right"]
0
[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]5[/TD]
[TD="bgcolor: transparent"]
person 4
[/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"]
Person 4
[/TD]
[TD="bgcolor: transparent, align: right"]
2
[/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent, align: right"]
0
[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]6[/TD]
[TD="bgcolor: transparent"]
Person 1
[/TD]
[TD="bgcolor: transparent, align: right"]
2
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"]
Person 6
[/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent, align: right"]
0
[/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent, align: right"]
0
[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]7[/TD]
[TD="bgcolor: transparent"]
Person 2
[/TD]
[TD="bgcolor: transparent, align: right"]
2
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"]
Person 17
[/TD]
[TD="bgcolor: transparent, align: right"]
1
[/TD]
[TD="bgcolor: transparent, align: right"]
0
[/TD]
[TD="bgcolor: transparent, align: right"]
0
[/TD]
[TD="bgcolor: transparent, align: right"]
0
[/TD]
[TD="bgcolor: transparent, align: right"]
0
[/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]8[/TD]
[TD="bgcolor: transparent"]
person 4
[/TD]
[TD="bgcolor: transparent, align: right"]
2
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]9[/TD]
[TD="bgcolor: transparent"]
Person 1
[/TD]
[TD="bgcolor: transparent, align: right"]
3
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]10[/TD]
[TD="bgcolor: transparent"]
Person 17
[/TD]
[TD="bgcolor: transparent, align: right"]
3
[/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
</tbody>[/TABLE]
Try this VBA code you will need to change ranges and the do until loop to match your data. I only do the loop until it is > 3 since your sample data goes to 3.
Code:
Sub survay()
Dim lrl As Long
Dim lrm As Long
Dim lc As Long
lrl = Cells(Rows.Count, 1).End(xlUp).Row
lrm = Cells(Rows.Count, 6).End(xlUp).Row
lc = Cells(1, Columns.Count).End(xlToLeft).Column
samep = 0
For x = 2 To lrm
For y = 7 To lc
If Cells(x, 6) = Cells(1, y) Then
Cells(x, y) = ""
Else
pnum = 1
Do Until pnum > 3
If Application.WorksheetFunction.SumIfs(Range("B2:B" & lrl), Range("A2:A" & lrl), Cells(x, 6), Range("B2:B" & lrl), pnum) > 0 And Application.WorksheetFunction.SumIfs(Range("B2:B" & lrl), Range("A2:A" & lrl), Cells(1, y), Range("B2:B" & lrl), pnum) > 0 Then
samep = samep + 1
pnum = pnum + 1
Else
pnum = pnum + 1
End If
Loop
Cells(x, y) = samep
samep = 0
End If
Next y
Next x
End Sub