vba script to return multiple results to a single cell using vlookup type formula

  • 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.


    code below.....



    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

  • Re: vba script to return multiple results to a single cell using vlookup type formula


    I'm not sure what is the problem. Does the code run but not do as you want, or does it error?


    Edit: seems to work for me if you subtract one from the offset.

  • Re: vba script to return multiple results to a single cell using vlookup type formula


    it works but makes my spreadsheet really slow and unresponsive.


    when you say subtract 1 from offset, you suggest I change the '0' to a "-1"?

  • Re: vba script to return multiple results to a single cell using vlookup type formula


    Reducing a value by 1 does not cause that error - sure you didn't delete something else unintentionally?


    Regardless, without the benefit of your revised code any suggestions are pure guesses. Save time, post the code

  • Re: vba script to return multiple results to a single cell using vlookup type formula


    Ok I think part of the error was something I did. I deleted the cells and started over and it seems fine now however the offset is wrong.I do not understand the offset rules in vba.
    when a match is made lets say 2 items, it returns one match and one result below the mach. I made all offsets zero and it does not change. do I need to do a step to implement the change other then just saving it?

  • Re: vba script to return multiple results to a single cell using vlookup type formula


    Actually I meant change the other offset, the column. I don't really understand what you're asking in your last post. Post a workbook which shows the problem, as cytop says will save us a lot of time.

  • Re: vba script to return multiple results to a single cell using vlookup type formula


    ok thank you. as you can see I have the formula in "all Portfolio" =MultiVLookup2([@Symbol],[Symbol],1) I've tried to change the offset as you suggested but for some reason the change does not seem to affect the formula results. as you can see the results do not line up, the formula is taking the information from "List" field but one box below the correct box, so the offset is 1 off some how. When I change the VBA code. nothing seems to change so I must be missing a step to implement the change. does that make sense?


    [TABLE="width: 588"]

    [tr]


    [td]

    Symbol

    [/td]


    [td]

    List

    [/td]


    [td]

    All Portfolio

    [/td]


    [/tr]


    [tr]


    [td]

    ACC

    [/td]


    [td]

    Quintile2

    [/td]


    [td]

    High Quality & Dividend Yield

    [/td]


    [/tr]


    [tr]


    [td]

    ADP

    [/td]


    [td]

    High Quality & Dividend Yield

    [/td]


    [td]

    Quintile2

    [/td]


    [/tr]


    [tr]


    [td]

    AGR

    [/td]


    [td]

    Quintile2

    [/td]


    [td]

    Quintile2

    [/td]


    [/tr]


    [tr]


    [td]

    AJG

    [/td]


    [td]

    Quintile2

    [/td]


    [td]

    High Quality & Dividend Yield

    [/td]


    [/tr]


    [tr]


    [td]

    AMGN

    [/td]


    [td]

    High Quality & Dividend Yield

    [/td]


    [td]

    Alpha Surprise Model

    [/td]


    [/tr]


    [tr]


    [td]

    AMT

    [/td]


    [td]

    Alpha Surprise Model

    [/td]


    [td]

    Alpha Surprise Model

    [/td]


    [/tr]


    [tr]


    [td]

    AMZN

    [/td]


    [td]

    Alpha Surprise Model

    [/td]


    [td]

    Alpha Surprise Model

    [/td]


    [/tr]


    [tr]


    [td]

    ANTM

    [/td]


    [td]

    Alpha Surprise Model

    [/td]


    [td]

    US 1, Quintile2

    [/td]


    [/tr]


    [tr]


    [td]

    ANTM

    [/td]


    [td]

    US 1

    [/td]


    [td]

    US 1, Quintile2

    [/td]


    [/tr]


    [tr]


    [td]

    ARE

    [/td]


    [td]

    Quintile2

    [/td]


    [td]

    Alpha Surprise Model

    [/td]


    [/tr]


    [tr]


    [td]

    AVB

    [/td]


    [td]

    Alpha Surprise Model

    [/td]


    [td]

    Quintile2, US 1

    [/td]


    [/tr]


    [tr]


    [td][/td]


    [td][/td]


    [td][/td]


    [/tr]


    [tr]


    [td][/td]


    [td][/td]


    [td][/td]


    [/tr]


    [/TABLE]

  • Re: vba script to return multiple results to a single cell using vlookup type formula


    something happened to that Worksheet when I was experimenting with VB. I started over on a new one and changed the Offset as you suggested and seems to work now. thank you trying to stick with me! :)

  • Re: vba script to return multiple results to a single cell using vlookup type formula


    yes everything worked out great, the suggested change in offset corrected the problem. I added several VBA scripts with similar names to the workbook and I was blindly changing the wrong one, not the one actually called upon in my formula. A very silly mistake. I was distracted by not understanding the code and messed up. there was no way for you guys to replicate my user error but I truly appreciate your patience.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!