Sum up rows with text

adamsm

Active Member
Joined
Apr 20, 2010
Messages
444
Hi anyone,

How could I figure out a code or formula that would sum up all the rows containing the text "My" in column "K" of the active sheet to cell "A1".

My data starts from row 17; meaning the column headers are in row 16.

Any help on this would be kindly appreciated.

Thanks in advance.
 
One last help If I may ask. The code sum ups all the rows where hidden or visible. How could it be changed in a manner so that it would sum up only the visible rows?
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try:
Code:
Sub CountMy ()
Application.ScreenUpdating = False
Dim i As Long, j As Long, k As Long
Range("A1:B1").ClearContents
For i = 6 To Range("K" & Rows.Count).End(xlUp).Row
  If Rows(i).Hidden = False Then
    If InStr(Range("K" & i), "My") > 0 Then Range("A1") = Range("A1").Value + 1
    If InStr(Range("K" & i), "Cat") > 0 Then Range("B1") = Range("B1").Value + 1
  End If
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
One more help if I may ask...I hope I'm not too late for this.

I'm having text in the format My/Family and My.

But the code counts My/family as 2 and My as 1 even though there is only one row of text containing My and My/Family?

How could I overcome this?

Any help on this would be kindly appreciated.

Thanks in advance.
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,111
Members
452,302
Latest member
TaMere

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