I'm using the VBA code below to add all results to a single cell. basically a list of stock tickers and then a name of a portfolio. if the same stock is in multiple portfolios the I get all the names of the relevant portfolios output into a single cell. this code is not passing the debugger & freezing up excel and causing it to move very slow. I found this code on another thread here and it seems to do what I need it to do but excel seems to not like it very much. a friend suggested the below changes to the script. I'm pretty ok with excel but VBA is beyond my understanding at the moment.
My vba syntax is very rusty but I noticed no false condition here. The IF statement acts if TRUE but doesn’t have a handler for the FALSE condition (unless XLS does something automatically as part of being a managed language). I’m not sure of the intention, but you could run the Next(cell) function within that loop and further nest the IF statements.
Public Function MultiVLookup2(MatchWith As String, TRange As Range, col_index_num As Integer) MatchWith = LCase$(MatchWith) If (MatchWith = "") Then MultiVLookup2 = "" Else For Each cell In TRange If LCase$(cell.Value) = MatchWith Then x = x & cell.Offset(0, col_index_num).Value & ", " End If Next cell If (x = "") Then MultiVLookup2 = "" Else MultiVLookup2 = Left(x, Len(x) - 2) End If End If End Function