Find Combinations, Delimit, and Paste into new Tab

  • I have bits and pieces of a VBA macro I'm trying to finish and I'm trying to tie it all together. I'm a novice at this and could really use some help finishing it so it all works smoothly.


    I currently have a working VBA macro to take a range of values in row2, and transpose and paste it vertically as many times as the value in B2. This works great already(see attached spreadsheet).


    From here I'm attempting to take these transposed vertical ranges, and use VBA recursively to spit out the combinations(permutations?) of the ranges the first macro came up with. I have working code that a friend had given to me, but I'm having difficulty tailoring it to my needs to be able to adjust it based on the variables I use for the first (working) macro. For example, in the spreadsheet linked below, I'd like the macro to select A5:A9, B5:B9, C5:C9, D5,D9 individually, and make every combination of values from these variables, and past that into G4.


    Here's my code so far:



    Then, once this range is pasted in G4, I wanted to select this range, and text to columns delimit by "/" somehow thru VBA (as it's a pain in the ass to keep doing this manually) if possible. Then select this whole range that was just delimited, copy, and paste into the "Analysis" tab starting in cell A1.



    I was hoping someone could at least point me in the right direction with a recursive algorithm. I'd like to make it dynamic enough to take varying numbers of columns and rows that my working macro already uses. I'd be really appreciative for any help at all!



    https://app.box.com/s/j76aymvyfsd5dskogw2a

  • Re: Find Combinations, Delimit, and Paste into new Tab


    Hi Pike,


    Not sure I understand what you're asking. Please let me know so I can clarify!

  • Re: Find Combinations, Delimit, and Paste into new Tab


    With the macro, I am trying to get the above code to output what I have in this screenshot here: https://app.box.com/s/3q91a1kml966tdmb5vtd


    I did this manually and it takes forever, but it gives you an idea of what I'm trying to accomplish if the above description was too vague. Does that help?


    Overall, the finalized data from the finished macro will be used for Monte Carlo simulations as part of an ongoing grad school project.

  • Re: Find Combinations, Delimit, and Paste into new Tab


    Multiples of the variables. So in this case with the example I posted, Month1 through Month4 can range from multiples of -2 to +2 (Each can be (month1*-2) to (month1*2)).


    The reason I would like it to reference the first macro I posted that works is to use it for a bunch of random tests and variables. I could potentially need to estimate 6 months using values from -5 to +5. But no greater than that. That's the absolute max, but I'd like to be able to to find the permutations/combinations of any inputs I have from the first macro, which spits out the variables in the matrix starting in A4.


    I have another macro that drills down that output that would be pasted from this finished code to copy and paste each combination's results on another set of variables. So this is the missing step in the middle of a very large project!!

  • Re: Find Combinations, Delimit, and Paste into new Tab


    I can't foresee ever needing to do that, if that's the case I'll find a workaround. Let's say for practical purposes (what I will use 99.9% of the time), I'd use up to 4 months and values of -3 to +3. That's honestly I think the max I'd ever use.


    Do you have any suggestions on how to edit what code I currently have in order for it to accomplish that? Any code samples would be GREATLY appreciated, so I can see how the code has changed from mine (I'm still learning so it helps immensely).

  • Re: Find Combinations, Delimit, and Paste into new Tab


    I already have some code made, can anybody off some advice on how to edit what I've already started with??

  • Re: Find Combinations, Delimit, and Paste into new Tab


    try...

  • Re: Find Combinations, Delimit, and Paste into new Tab


    Oh wow! That's a ton for me to browse through, thanks! I did get erroneous results however. When doing it the long way with a Month # of 3 and values of -2,-1,0,1,2 there's 126 different combinations. The code above only returns 64.


    Why is this?

  • Re: Find Combinations, Delimit, and Paste into new Tab


    this is still slow but will allow greater repeated combinations of unquie values

Participate now!

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