+ Reply to Thread
Results 1 to 3 of 3

Go to Next case in a Select Statement?

  1. #1
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Go to Next case in a Select Statement?

    I'm building a little program in Excel for no reason other than teaching myself basic VBA skills, and I've run into a snag I can't quite figure out. The program is to generate a maze using borders, I have four Subs for making the borders, GoLeft, GoRight, GoDown, GoUp. I am using the below code to generate the path, using a Select Case of a RANDBETWEEN(1,4) to randomize the direction.

    I have worked out how to not backtrack, as in it will not go the opposite direction the last loop went. If it goes DOWN, it cannot go UP on the next pass.

    The problem I am having is the pathway always tends to loop back over itself. I have determined the way to correct this would be to drop a number into each cell as the path generates, representing the direction of turn that cell encountered, and to use an IF statement within each case?

    tl;dr: If Case 1 is selected, how can I leave Case 1 and go to Case 2, if a given condition is met? Or do I just need to nest another level of Select Case?

    Please Login or Register  to view this content.



    Since this is a learning exercise for me, I don't need/want the code to be written for me, I just need to know what angle to attack this problem from.

    Thanks!
    You should hit F5, because chances are I've edited this post at least 5 times.
    Example of Array Formulas
    Quote Originally Posted by Jacc View Post
    Sorry, your description makes no sense. I just made some formula that looks interesting cause I had nothing else to do.
    Click the * below on any post that helped you.

  2. #2
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Go to Next case in a Select Statement?

    Here to make things simpler and to see exactly what I'm doing, do the following:
    Select every cell and make them square to make it look not weird, I'm using 20x20 pixel
    in cell A1 put =RANDBETWEEN(1,4)

    Drop all the below into a new module and run BeginMap

    Please Login or Register  to view this content.
    Criticism on how I'm doing this is welcome!
    Last edited by Speshul; 07-25-2014 at 09:57 AM.

  3. #3
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Go to Next case in a Select Statement?

    Well, my Mother, who knows absolutely nothing about VBA, got me a lot closer. She wants to know more about Excel for her work, and was asking about VBA and thought this was a good visual example of something VBA can do (apply borders, insert values into cells) and I told her what my problem was. She said "well why don't you just put two borders instead of three each time a cell is selected?", because for Down I had a U shaped border, Left was a C shape, and so on. I modified it to only top and bottom border left and right turns, and only left and right on Up ad Down turns. It leaves the edges rough, but it makes a more maze-like maze!



    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Select Case statement
    By gr8fasushi in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-03-2011, 12:44 PM
  2. [SOLVED] Utilize a Select Case Statement in Target Intersect Statement
    By max57 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-29-2009, 08:55 PM
  3. Select Case Statement
    By Juw in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-14-2007, 03:11 AM
  4. Select Case Statement Help
    By Jeugo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-27-2006, 03:45 PM
  5. select case statement
    By jrd269 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-03-2005, 12:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1