Separate duplicate riders in excel worksheet -
i have workbook 4d barrel racing jackpots designed. perfect in it, except want able make sure duplicate riders separated @ least 10 rows. possible? if so, how?
i know how find , rid of duplicates. that's not problem. want separate them each other.
thanks!
take @ below example based on elements reallocation hold queues. takes input data column a, process it, , outputs result column b.
option explicit sub separate() dim nseparate long dim cqholds object dim qinput object dim qresult object dim long dim nlength long dim content variant dim sqname variant dim sqtarget variant ' set number of rows separate nseparate = 4 ' init objects set cqholds = createobject("scripting.dictionary") set qinput = createobject("system.collections.queue") set qresult = createobject("system.collections.queue") ' push data worksheet column input queue = 1 content = thisworkbook.sheets("data").cells(i, 1).value if content = "" exit qinput.enqueue content = + 1 loop ' reallocate input queue elements hold queues while qinput.count > 0 ' pull 1 element input queue content = qinput.dequeue ' create hold queue element if not exists if not cqholds.exists(content) set cqholds(content) = createobject("system.collections.queue") ' push element hold queue cqholds(content).enqueue content ' push nseparate empty trailing places hold queue = 1 nseparate cqholds(content).enqueue "" next loop ' retrieve elements hold queues result queue ' search longest hold queue non-empty element on exit nlength = 0 each sqname in cqholds if cqholds(sqname).peek <> "" , cqholds(sqname).count > nlength nlength = cqholds(sqname).count sqtarget = sqname end if next ' target queue not found if nlength = 0 exit ' pull 1 empty place each hold queue each sqname in cqholds if cqholds(sqname).peek = "" cqholds(sqname).dequeue if cqholds(sqname).count = 0 cqholds.remove sqname next ' pull element target queue , push result queue qresult.enqueue cqholds(sqtarget).dequeue if cqholds(sqtarget).count = 0 cqholds.remove sqtarget loop ' force push remaining in hold queues elements result queue nlength = qresult.count while cqholds.count > 0 each sqname in cqholds content = cqholds(sqname).dequeue if content <> "" qresult.enqueue content if cqholds(sqname).count = 0 cqholds.remove sqname next loop if qresult.count > nlength msgbox "can't arrange " & (qresult.count - nlength) & " last elements" ' pull data result queue worksheet column b = 1 while qresult.count > 0 thisworkbook.sheets("data").cells(i, 2).value = qresult.dequeue = + 1 loop end sub
here sample code testing, number of rows separate set 4:
Comments
Post a Comment