+ Reply to Thread
Results 1 to 6 of 6

Multiple else if loops - problem with placement of end for/if

  1. #1
    Registered User
    Join Date
    02-06-2014
    Location
    derby
    MS-Off Ver
    Excel 2013
    Posts
    8

    Multiple else if loops - problem with placement of end for/if

    Hi there.

    I want to run a loop that sets variables depending on which worksheet it is looking at, then sets more variables depending on the column within the worksheet.

    in the first instance it finds the worksheet - if the worksheet is called valve it will choose find a column and set variables. I then want it to skip to the code at the bottom. after it has run the code i want it to search for another column in the valve sheet and repeat the code for each column. After that I want it to search for the sheet 'pipe' and do the same. Eventually the loop will include 6 such sheet names each with multiple columns to set variables for.

    At the moment when I run the code it exits the loop too quickly so that non of the code at the bottom is run for any of the sheets. I've been moving the end if/end for all over the show but so far haven't found a solution. Any help much appreciated. Cheers

    Please Login or Register  to view this content.


  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Multiple else if loops - problem with placement of end for/if

    Try using select case it will be easier

    select case worksheet name

    case "Sheet1"

    select case worksheet.column

    case 2

    case 5

    case 10
    end select

    case "Sheet2"

    select case worksheet.column

    case 2

    case 5

    case 10
    end select


    End select

    Have a look on help, a lot easier i think.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Registered User
    Join Date
    02-06-2014
    Location
    derby
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Multiple else if loops - problem with placement of end for/if

    Thanks, I'd forgotten all about case.
    However, I'm not sure how I can get the macro to run the code at the bottom for each case? should i make the code a separate function? Not working with this solution so far as it doesn't run the code for the f(X) filter. I also get the error 'out of memory' if I run it without 'call filter'

    thanks againg

    Please Login or Register  to view this content.
    Last edited by squarahollier; 05-02-2014 at 06:45 AM.

  4. #4
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Multiple else if loops - problem with placement of end for/if

    Out of memory is a funny one. It comes when you are running some code on a sheet that has zoom applied, i've found, check your sheet is at 100% zoom.

  5. #5
    Registered User
    Join Date
    02-06-2014
    Location
    derby
    MS-Off Ver
    Excel 2013
    Posts
    8

    Re: Multiple else if loops - problem with placement of end for/if

    It was on 100% already

  6. #6
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Multiple else if loops - problem with placement of end for/if

    ok, where does it tell you you're out of memory, if you debug it.

+ 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. Pivot table field placement/layout problem
    By HannahKirk in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 01-21-2014, 09:50 PM
  2. Nested loops problem
    By Symplystyc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-24-2011, 02:24 AM
  3. LOOPs problem
    By Emmett423 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2006, 02:43 PM
  4. problem with for and next loops
    By mikewild2000 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-29-2005, 12:26 PM

Tags for this Thread

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