reefswaggie,
I'm not convinced you need VBA for this task. Attached is an example workbook based on the criteria you described.
In column C is a list of random numbers between 0 and 9 going from C5 to C1004 (so there are 1000 random numbers acting as Action ID's as you described).
In cell F11 and copied over and down to F211 is this array formula:
=IFERROR(INDEX($C$6:$C$1004,SMALL(IF($C$5:$C$1003=F$10,ROW(INDIRECT("1:"&COUNTA($C$5:$C$1003)))),ROW()-ROW(F$10)))," ")
Note that array formulas must be entered with Ctrl+Shift+Enter and not just Enter.
That array formula gets the following action ID's for each action. So it gets every action ID that followed action 0 from the list in column C.
Then, to show the most common action that came after each action ID, cell F8 and copied over contains this regular (non-array) formula:
=INDEX(F11:F211,MATCH(MAX(INDEX(COUNTIFS(F11:F211,"<> ",F11:F211,F11:F211),)),INDEX(COUNTIFS(F11:F211,"<> ",F11:F211,F11:F211),),0))
Bookmarks