'How to find the frequency of each criteria in the same column in Excel VBA

''' Sub SummaryDemographics()

Set dt = Worksheets("Data")
Set ans = Worksheets("Answer")
Set s1 = Worksheets("Summary 1")

'print headers
j = 2
i = 1
LR = 0
For i = 1 To 6: 'loop rows in 'Answer' sheet
    s1.Cells(LR + 1, 1) = ans.Cells(i, 1) 'question
    s1.Cells(LR + 1, 2) = "Percentage"
    For j = 2 To 7: 'loop through columns in 'answer' sheet
        Do Until ans.Cells(i, j).Value = ""
            LR = s1.Cells(Rows.Count, 1).End(xlUp).Row + 1
            s1.Cells(LR, 1) = Right(ans.Cells(i, j), Len(ans.Cells(i, j)) - 2)
            s1.Cells(LR, 2) = WorksheetFunction.CountIf(dt.Cells(9, i + 1).End(xlDown), i)
            j = j + 1
        Loop
    Next j
    LR = LR + 1
Next i

End Sub'''

Data Source Format of answer

The above coding is what I tried out, but it cannot count the frequency of each variable in the column. Like for sex, it's output is 1 and 1 for male and female respectively. I haven't tried to calculate the percentage, since I can't even count the frequency of each variable



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source