Solved

Create a macro: formula to show count how many consecutive alphabet in a spreadsheet

Posted on 2012-09-20
278 Views
See attached sheet.
Consecutives-count.xls

I  need to show the following :

Column P to have a show how many times "A" occured consecutively for 3 times

Column Q to show how many times "A" occured consecutively for 6 times

Column R to show how many times "A" occured consecutively for more than 6 times
0
Question by:ceneiqe

LVL 24

Expert Comment

OK in the workbook attached is the following formula:

This allows you to select what you are looking for and how many times to triger the count...
``````Function ConsecutiveCount(Letter As String, Occurence As Integer, TheRange As Range) As Integer
Dim i As Long
For Each c In TheRange
If c.Value = Letter Then
i = i + 1
If i >= Occurence Then ConsecutiveCount = ConsecutiveCount + 1
Else
i = 0
End If
Next
End Function
``````
Please note that the second "A" in about the third line had a space in it... so was in error...
maybe a find replace " " to correct this on all or changing the  If c.Value = Letter Then to  If c.Value like "*" & Letter & "*" Then will fix that.
Consecutives-count.xls
0

Author Comment

"Please note that the second "A" in about the third line had a space in it... so was in error..."

I didn't see any error. Consecutives-count--1-.xls

Which exact cell are you refering to ?

Is it possible to run auto by pressing alt f8 and run ?
0

LVL 24

Accepted Solution

There is no need to 'run' the Function will behave like other in-build Excel functions.
You just need to change the number of occurences from 3.

If you chnage it to 1 then you will effectively get a "count", this will highlight the rows with spaces in them.

Attached file will ignore spaces and work with your existing data.
Consecutives-count.xls
0

Featured Post

Suggested Solutions

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.