Message Box showing number of times a certain word followed by a digit occurs first in rows in column

Ironman

Well-known Member
Joined
Jan 31, 2004
Messages
1,069
Office Version
  1. 365
Platform
  1. Windows
Hi

Sheet 'Training 1981-1997' Column F2:F6210 contains text, with some rows that start with the word "Day" (without the commas) followed by a space and a number.

I need to cross-check to make sure I haven't skipped or duplicated a number in error. Therefore what I'd be grateful for is some double click event code I can run in any cell in Col G that will return a msgbox that has counted the number of cells in Col F2:F6210 with text beginning with the word "Day" followed by a space and a digit e.g. "Day 123". I've used the 'Find' function to do this so far, but it'll be faster just to double click.

Many thanks!
 
Last edited:
OK:
Try this:
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Modified  2/6/2022  10:39:22 AM  EST
If Target.Column = 7 Then
Application.ScreenUpdating = False
Cancel = True
Dim r As Range
Dim e As Long
e = 0
For Each r In Range("F2:F6210")
    If r.Value Like "*Day *" Then e = e + 1
Next
End If
MsgBox "We found " & e & " occurances"

Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try this macro in the worksheet code module:
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.CountLarge > 1 Then Exit Sub
    Application.ScreenUpdating = False
    Dim lRow As Long, v As Variant, i As Long, x As Long
    lRow = Range("F" & Rows.Count).End(xlUp).Row
    If Intersect(Target, Range("G" & lRow)) Is Nothing Then Exit Sub
    v = Range("F2:F" & lRow).Value
    For i = LBound(v) To UBound(v)
        If v(i, 1) Like "Day *" And IsNumeric(Mid(v(i, 1), 5)) Then
            x = x + 1
        End If
    Next i
    Application.ScreenUpdating = True
    MsgBox x
End Sub
 
Upvote 0
Thanks MAIT - I've double clicked a few cells in Col G and it won't run.
 
Upvote 0
Did you try the macro I suggested in Post #12?
 
Upvote 0
Sorry Mumps, I posted within seconds of seeing your post - many thanks, I'm trying it now.

Edit: Same thing as with MAIT's solution - I'm double clicking cells in Col G and nothing's happening. Is there a specific row I need to be trying this with or should it work with all the rows?
 
Upvote 0
Yes, exactly as you said. I'm sorry that it isn't working.
The script looks in column F for a value like "Day " and any other value
Do you have a value in column F or a formula

And when you say Day I assume you mean the word "Day " and not Todays Date

Show us a example of exactly what you have in column F
And the script looks in the range you said:
Like:
For Each r In Range("F2:F6210")
 
Upvote 0
Doesn't your existing Worksheet_BeforeDoubleClick have code to exit the sub under certain conditions ?
 
Upvote 0
The script looks in column F for a value like "Day " and any other value
Do you have a value in column F or a formula

And when you say Day I assume you mean the word "Day " and not Todays Date

Show us a example of exactly what you have in column F
And the script looks in the range you said:
Like:
For Each r In Range("F2:F6210")
Col F contains only text.

Yes, Day.

Sure:
Slight pain still from L. shin. WEEK TOTAL = 11 MILES
Day 327. Evening run. Steady pace. Legs still not v. lively for some reason. Left shin not a problem although discomfort there.
Day 328. Evening run. Fast, hard run. Legs better than above but don't feel as light as normal. Not much power in lungs/legs on hills.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,854
Members
449,051
Latest member
excelquestion515

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