您的位置首页百科问答

excel统计姓名各个字的数量

excel统计姓名各个字的数量

这个问题稍麻烦点,需要通过VBA来实现。下面的模块放在sheet1,假设 sheet1的A列是姓名,总共100行。然后执行。计算结果将放在sheet2,A列是出现过的汉字,B列是该汉字出现的次数Sub TongJi()Sheet2.Range("A:B").ClearContents '每衫亏次执行先清空统计结果漏塌滑Dim i, j, k, m As IntegerDim x1, x2 As StringFor i = 1 To 100 '可以调整100为实际行数,数较大时可能计算会返腊稍慢些x1 = Cells(i, 1)For j = 1 To Len(x1)x2 = Mid(x1, j, 1)m = Sheet2.[A65536].End(xlUp).Row For k = 1 To m If Sheet2.Cells(k, 1) = x2 Then Sheet2.Cells(k, 2) = Sheet2.Cells(k, 2) + 1 Exit For End If Next k If k > m Then Sheet2.Cells(k, 1) = x2 Sheet2.Cells(k, 2) = 1 End IfNext jNext iEnd Sub