Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default counting consecutive repeated values in a column along with the range


can you help me with a script to count as well as note the position o
the consecutive repeated values in a column. like one saying that 3-5
9-11, 6001-6003 had the value 1 in them. Thanks

--
g
-----------------------------------------------------------------------
g s's Profile: http://www.excelforum.com/member.php...fo&userid=2426
View this thread: http://www.excelforum.com/showthread.php?threadid=46998

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default counting consecutive repeated values in a column along with the range

The following macro should work
You will need to set up the column which has the values as a named range
("therange")
It puts the results in the column to the right of the one with the values in
it.


Public Sub countvalues()
Dim thecurrentrow%
Dim thetargetrow%
Dim thisvalue
Dim oldvalue
Dim firstflag As Boolean

firstflag = True 'checks to see if this is the first loop
thetargetrow = 1 'this is the row in the target column where you wish to
result list to start
For Each c In Range("therange") ' name the range of the column you wish to
count
therow = c.Row
thecol = c.Column
thisvalue = c.Value 'finds the current value
If thisvalue = oldvalue Then 'if this loop has the same value as the
previous one it works out what the last row no was
lastrow = therow
lastcol = thecol
Else
If Not firstflag Then
'when the current cell value differs from the previous cell value it
'writes out the start row - end row (value of range)
'note it does this when there is only a single itteration of the
value
'if you want to stop this behaviour put an If then else statement
around the next two lines
'if lastrow < firstrow then....else...endif
Range(Cells(thetargetrow, thecol + 1), Cells(thetargetrow, thecol +
1)).Value = firstrow & " - " & IIf(lastrow firstrow, lastrow, firstrow) &
"(" & oldvalue & ")"
thetargetrow = thetargetrow + 1
Else
'picks up the endrow values for the initial loop
lastrow = therow
lastcol = thecol
firstflag = False
End If
firstrow = therow
firstcol = thecol
End If
oldvalue = thisvalue



Next c
End Sub


"g s" wrote in message
...

can you help me with a script to count as well as note the position of
the consecutive repeated values in a column. like one saying that 3-5,
9-11, 6001-6003 had the value 1 in them. Thanks.


--
g s
------------------------------------------------------------------------
g s's Profile:

http://www.excelforum.com/member.php...o&userid=24263
View this thread: http://www.excelforum.com/showthread...hreadid=469983



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting strings of consecutive numbers in a column SamG Excel Discussion (Misc queries) 1 January 27th 10 07:25 AM
Counting repeated data in a column freeman Excel Worksheet Functions 3 July 7th 08 02:33 AM
counting blanks in a non-consecutive range jenniebentham Excel Discussion (Misc queries) 3 November 21st 07 01:38 PM
Counting a specific range of values within a column kenm Excel Discussion (Misc queries) 7 January 2nd 07 08:34 PM
create list of unique values from a column with repeated values? Chad Schaben Excel Worksheet Functions 1 July 8th 05 10:25 PM


All times are GMT +1. The time now is 06:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"