ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Tally occurences of phrase on one sheet. (https://www.excelbanter.com/excel-discussion-misc-queries/56164-tally-occurences-phrase-one-sheet.html)

RYD@wolpofflaw

Tally occurences of phrase on one sheet.
 
I have several sheets of information. What I'm looking to do is tally the
occurences of a specific phrase "ABC" in one column, and place that tally on
a separate sheet. Anyone have any ideas.

Kevin B

Tally occurences of phrase on one sheet.
 
The following code assumes that the data starts in column A, row 1 on a
worksheet that is not Sheet3 and that the workbook has at least 3 worksheets.

The macor is run while you are in the sheet containing the data you wish to
count

Sub CountABC()

Dim varVal As Variant
Dim lABCCount As Long
Dim lOffset As Long

Range("A1").Select
varVal = ActiveCell.Value

'loop down column A and count each occurrence of the
'string ABC storing to a variable lABCCount
'Increment the row offset variable lOffset by 1 and pick
'up the value in the next cell in column A

Do Until varVal = ""
If varVal = "ABC" Then
lABCCount = lABCCount + 1
End If
lOffset = lOffset + 1
varVal = ActiveCell.Offset(lOffset).Value
Loop

'Activate Sheet3 and select cell A1
'Post the count value
Sheets("Sheet3").Activate
Range("A1").Select
ActiveCell.Value = lABCCount

End Sub

--
Kevin Backmann


"RYD@wolpofflaw" wrote:

I have several sheets of information. What I'm looking to do is tally the
occurences of a specific phrase "ABC" in one column, and place that tally on
a separate sheet. Anyone have any ideas.



All times are GMT +1. The time now is 09:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com