Count number of rows which contain specific text

taykaisheng

New Member
Joined
Jul 30, 2013
Messages
10
Hi, I am on an assignment to count the number of rows which contain specific text and print the value on email. However I'm stuck here

Here are my code

Code:
Public Function First()Dim Source As Workbook
Dim Var1 As Integer
Dim Var10 As Integer
Dim Source2 As Workbook


    
    Set Source = Workbooks.Open("C:\Users\HP\Desktop\IN INPROG.xlsx")
    
    Var1 = Application.WorksheetFunction.CountIf(Range("M1:M100"), "Orange")
   
    Source.Close SaveChanges:=False
    
    Set Source2 = Workbooks.Open("C:\Users\HP\Desktop\SR INPROG.xlsx")
    
    Var10 = Application.WorksheetFunction.CountIf(Range("M1:M100"), "Orange")
    
    Source2.Close SaveChanges:=False
    
    eTo = "orange@aod.au"
    esubject = Format(Date, "d/mmmm/yyyy") & " " & "Weekly Open Incident Reminder"
    ebody = "Dear All," & vbCrLf & "" & vbCrLf & "" & vbCrLf & "Orange: " & "SR: " & Var10 & " IN: " & Var1 
    
    Set app = CreateObject("Outlook.Application")
    Set itm = app.createitem(0)
    On Error Resume Next
    With itm
    .Subject = esubject
    .To = eTo
    .body = ebody
    .display

My current code will return all the value as "0" eventhough "Orange" does exist in one of the row. Hope someone could help me to solve the problem. Thank You
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi, I am on an assignment to count the number of rows which contain specific text and print the value on email. However I'm stuck here

Here are my code

Code:
Public Function First()Dim Source As Workbook
Dim Var1 As Integer
Dim Var10 As Integer
Dim Source2 As Workbook


    
    Set Source = Workbooks.Open("C:\Users\HP\Desktop\IN INPROG.xlsx")
    
    Var1 = [B][COLOR=#a52a2a]Application.WorksheetFunction.CountIf(Range("M1:M100"), "Orange")[/COLOR][/B]
   
    Source.Close SaveChanges:=False
    
    Set Source2 = Workbooks.Open("C:\Users\HP\Desktop\SR INPROG.xlsx")
    
    Var10 = [B][COLOR=#a52a2a]Application.WorksheetFunction.CountIf(Range("M1:M100"), "Orange")[/COLOR][/B]
    
    Source2.Close SaveChanges:=False
    
    eTo = "orange@aod.au"
    esubject = Format(Date, "d/mmmm/yyyy") & " " & "Weekly Open Incident Reminder"
    ebody = "Dear All," & vbCrLf & "" & vbCrLf & "" & vbCrLf & "Orange: " & "SR: " & Var10 & " IN: " & Var1 
    
    Set app = CreateObject("Outlook.Application")
    Set itm = app.createitem(0)
    On Error Resume Next
    With itm
    .Subject = esubject
    .To = eTo
    .body = ebody
    .display

My current code will return all the value as "0" eventhough "Orange" does exist in one of the row. Hope someone could help me to solve the problem. Thank You
Try changing the red highlighted parts to this...

Application.WorksheetFunction.CountIf(Range("M1:M100"), "*Orange*")

Note the asterisks (wildcard symbols) around the word "Orange".
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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