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

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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,215,972
Messages
6,128,015
Members
449,414
Latest member
sameri

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