Function CountPJMOccurrences(cellValue As String) As Long
Dim selections() As String
Dim i As Long
Dim countPJM As Long
' Split cell contents based on comma
selections = Split(cellValue, ",")
' Loop through the array and count occurrences of "PJM"
For i = LBound(selections) To UBound(selections)
If Trim(selections(i)) = "PJM" Then
countPJM = countPJM + 1
End If
Next i
CountPJMOccurrences = countPJM
End Function
Function CountAESOOccurrencesInColumn() As Long
Dim ws As Worksheet
Dim cell As Range
Dim countAESO As Long
' Set the worksheet
Set ws = ThisWorkbook.Sheets("RFP_Details")
' Initialize count
countAESO = 0
' Loop through all cells in column E
For Each cell In ws.Range("E:E")
If InStr(1, cell.Value, "Canada-AESO", vbTextCompare) > 0 Then
countAESO = countAESO + 1
End If
Next cell
' Return the count
CountAESOOccurrencesInColumn = countAESO
End Function
2条答案
按热度按时间cpjpxq1n1#
试试这个案例:
字符串
您可以在工作表中使用此函数;例如,如果包含“排序列表”的单元格位于单元格E1中,则可以在F1中输入以下公式:
型
e1xvtsh32#
我使用GPT来构建Mark的答案,最后使用了这个,它起作用了。
字符串