excel中如何计算一个单元格里面重复的频率

来源:百度知道 编辑:UC知道 时间:2024/05/10 07:26:37
我把102个有重复的只有ABC的字母放在一个单元格里面 我想找出A有多少个,B有多少个,C有多少个,怎样计算

首先我假设你的数据在A1中.结果分别显示在B1,C1,D1中.
按下ALT+F11,复制下列代码.然后按下F5运行即可

Sub AAAA()
Dim A As Integer
Dim B As Integer
Dim C As Integer
Dim D As Integer
Range("A1").Select
D = Len(Selection)
For X = 1 To D
If Mid(Selection, X, 1) = "A" Then
A = A + 1
Else
If Mid(Selection, X, 1) = "B" Then
B = B + 1
Else
If Mid(Selection, X, 1) = "C" Then
C = C + 1
End If
End If
End If
Next
Range("B1").Select
ActiveCell.Value = "A:" & A & "个"
Range("C1").Select
ActiveCell.Value = "B:" & B & "个"
Range("D1").Select
ActiveCell.Value = "C:" & C & "个"
End Sub