我有一個帶有標題的數據工作表。我試圖在VBA中找到帶有「type」標題的列,然後在該列中計算字符串「x」出現的次數,即計算「add」出現在標題爲「type」的列中的次數。找到名稱爲「x」的列,並在該列中計算出現的單詞
我知道你可以創建一個腳本字典來計算每個單詞出現的次數,我遇到了通過標題搜索來查找「type」列的問題。
到目前爲止我的代碼看起來在每一個細胞的表,但是我只是想將其限制於列「類型」:
Dim shtSheet1 As String
Dim dict As Object
Dim mycell As Range
shtSheet1 = "Test"
Set dict = CreateObject("Scripting.Dictionary")
dict.Add "Add", 0
dict.Add "Delete", 0
dict.Add "Update", 0
For Each mycell In ActiveWorkbook.Worksheets(shtSheet1).UsedRange
If dict.Exists(ActiveWorkbook.Worksheets(shtSheet1).Cells(mycell.Row, mycell.Column).Value) Then
dict(ActiveWorkbook.Worksheets(shtSheet1).Cells(mycell.Row, mycell.Column).Value) = dict(ActiveWorkbook.Worksheets(shtSheet1).Cells(mycell.Row, mycell.Column).Value) + 1
End If
Next
感謝您的幫助!