Count word even if other words are in same line help

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,227
Office Version
  1. 2010
Platform
  1. Windows
Hello good evening hope you can help me please? I have the code below which works great and it counts the word ‘CAG’. But it doesn’t count if their is another word before or after it. For example ‘cancelled cag’ or ‘cag replanned’. Hope you can help please.

VBA Code:
Private Sub userform_initialize()
Dim j As Long
j = Application.WorksheetFunction.CountIf(ThisWorkbook.Sheets("In Day VL").Range("A:A"), "CAG",)
 UserForm1.TextBox2.Value = j
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Use wild cards?
 
Upvote 0
Use wild cards?
Hi i have no idea what a wild card is sorry, I am a beginner in vba
 
Upvote 0
Did you follow the link and read the CountIf solution? You are able to research suggestions you don't understand, yes?

You will likely only ever need one of the first 3 in this list
Give it a try.
 
Upvote 0
Hi i have no idea what a wild card is sorry, I am a beginner in vba
Hi i have just tried editing the code to the below but it still didnt work, hope you can help please?

VBA Code:
Private Sub userform_initialize()
Dim j As Long
Dim occurance As Integer
j = Application.WorksheetFunction.CountIf(ThisWorkbook.Sheets("In Day VL").Range("A:A"), "CAG")
occurance = WorksheetFunction.CountIf(Cells, "*" & Search & "*")
End Sub
 
Upvote 0
Did you follow the link and read the CountIf solution? You are able to research suggestions you don't understand, yes?

You will likely only ever need one of the first 3 in this list
Give it a try.
Hi I have tried several codes now still cant get it to work. Hope you can help me please?
 
Upvote 0
Your example uses no wild cards. Did you read the solution at the link or not?
Try
j = Application.WorksheetFunction.CountIf(ThisWorkbook.Sheets("In Day VL").Range("A:A"), "*CAG*")

I see no reason to concatenate the wild cards in the given example there, unless one wants to use a variable instead of the literal "CAG"
 
Upvote 0
Your example uses no wild cards. Did you read the solution at the link or not?
Try
j = Application.WorksheetFunction.CountIf(ThisWorkbook.Sheets("In Day VL").Range("A:A"), "*CAG*")

I see no reason to concatenate the wild cards in the given example there, unless one wants to use a variable instead of the literal "CAG"
That works a treat thank you cant believe it was just a '*' infront the cag and after, i did try other things but didnt fully understand the wild card.
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top