回顾不同细胞中的单词数量

时间:2017-03-07 22:26:32

标签: excel vba excel-vba excel-formula user-experience

在我的工作表“下载”中。

在C栏中我有:

BRONZE
SILVER
SILVER
BRONZE
GOLD
PLATIN
PLPLUS
AMBASS
PLPLUS 
etc...

我想做的是

in the cell J7: Bronze: "Total of Bronze"  
in the cell J8: Silver: "Total of Silver"  
in the cell J9: Gold: "Total of Gold"  
in the cell J10:Platinum "Total of PLATIN" 
in the cell J11:Platinum Plus "Total of PLPLUS" 
in the cell J12:Ambassador "Total of AMBASS" 
in the cell J13:Total "Total of Bronze, silver, gold, platin, plplus & Ambass"

我不认为对于那些了解vba的人来说很难回答。

2 个答案:

答案 0 :(得分:1)

对于Excel公式在 J1

上尝试此操作

<强> ="Total of " & COUNTIFS(C:C,C1) & " " & C1

答案 1 :(得分:1)

我不确定你为什么要在VBA中这样做,但是因为你坚持认为它需要:

Sub CountThem
    With Worksheets("Download")
        .Range("J7").Value = "Bronze: " & Application.CountIf(.Range("C:C"), "Bronze")
        .Range("J8").Value = "Silver: " & Application.CountIf(.Range("C:C"), "Silver")
        .Range("J9").Value = "Gold: " & Application.CountIf(.Range("C:C"), "Gold")
        .Range("J10").Value = "Platinum: " & Application.CountIf(.Range("C:C"), "PLATIN")
        .Range("J11").Value = "Platinum Plus: " & Application.CountIf(.Range("C:C"), "PLPLUS")
        .Range("J12").Value = "Ambassador: " & Application.CountIf(.Range("C:C"), "AMBASS")
        .Range("J13").Value = "Total: " & _
                              (Application.CountIf(.Range("C:C"), "Bronze") + _
                               Application.CountIf(.Range("C:C"), "Silver") + _
                               Application.CountIf(.Range("C:C"), "Gold") + _
                               Application.CountIf(.Range("C:C"), "PLATIN") + _
                               Application.CountIf(.Range("C:C"), "PLPLUS") + _
                               Application.CountIf(.Range("C:C"), "AMBASS"))

    End With
End Sub