Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Counting strings of consecutive numbers in a column | Excel Discussion (Misc queries) | |||
Counting repeated data in a column | Excel Worksheet Functions | |||
counting blanks in a non-consecutive range | Excel Discussion (Misc queries) | |||
Counting a specific range of values within a column | Excel Discussion (Misc queries) | |||
create list of unique values from a column with repeated values? | Excel Worksheet Functions |