View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen[_2_] Per Jessen[_2_] is offline
external usenet poster
 
Posts: 703
Default counting a specific "text" occurance in a selection of sheetswithin a workbook

If the sheets are placed as the first 12 tabs, it can be done like
this:

Sub countjune()
Dim ws As Worksheet
Dim mycol As Range
Dim mc As Long
Dim shIndex As Long

For shIndex = 1 To 12
Set ws = Worksheets(shIndex)
Set mycol = ws.Columns("N")
mc = mc + Application.CountIf(mycol, "Hello")
Next
MsgBox mc
End Sub

Regards,
Per

On 26 Sep., 18:13, Johnnyboy5 wrote:
Hi

can anyone help me modify the macro below that Don sent to me.

I need it to select a specific range of worksheets. * example sheets
1 to 12 *named *(April, May, June, July ....etc)

rather than selecting all the sheets in the workbook.

thanks

Johnny

Don Guillett Excel MVP
View profile
*More options 26 Sep, 13:26
On Sep 26, 4:30 am, Johnnyboy5 wrote:

- Show quoted text -
This might be quicker than a loop for text.
Option Explicit
Sub countjune()
Dim ws As Worksheet
Dim mycol As Range
Dim mc As Long
For Each ws In Worksheets
Set mycol = ws.Columns("N")
mc = mc + Application.CountIf(mycol, "Hello")
Next ws
MsgBox mc
End Sub