By using vba.booksticle.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

948 Steps to 6 Figures by Learning Excel-VBA and Other Skills



Step 868 - CountIfString(sCol,sValue) - counts the # of times the svalue appears in sCol




Function CountIfString(sCol, sValue)

Range(sCol & "1").Select
r = findlastrow(cl(sCol))
Range(sCol & "1:" & sCol & r).select
svSheet = ActiveSheet.Name
CreateSheet "TempForCount"

Selection.Copy
Sheets("TempForCount").Select
Activesheet.Paste
Application.CutCopyMode = False
Selection.Autofilter
r = FindLastRow(1)
ActiveSheet.Range("A1:A" & r).Autofilter field:=1, Criteria1:="=*" & sValue & "*"
CountIfString = [=subtotal(3,A:A)-1] ' -1 to not count header
Sheets(svSheet).Select
End Function


   Table of Contents | Send us your feedback | © 2025 All Rights Reserved | Edit