+ Reply to Thread
Results 1 to 6 of 6

Trouble with creating new worksheets using cell values with multiple loop conditions

  1. #1
    Registered User
    Join Date
    10-01-2013
    Location
    India
    MS-Off Ver
    Excel 2007 & Excel 2010
    Posts
    7

    Post Trouble with creating new worksheets using cell values with multiple loop conditions

    Hi All

    I am just beginner on Excel vba and need your help.

    I have a sheet which has Country name field (In Column A) and their status field (In Column C).
    Please see below image from my file for your reference.
    IMAGE.JPG
    I want macro to create a new worksheet for countries where the status is "Yes" and should name it according to that country. If the status is " No" then it should move to next country. This should continue until all the countries are checked in column A.

    Eg: If the status for Australia is "Yes" then the macro should create new worksheet with name Australia, If it's no then it should move to Bahrain.

    I tried below the below code (using help from internet) but it is not working.
    Your help will make my work more easy

    When i try to run the below macro it gives me Compile error : Next without For


    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by johnygaddar; 10-02-2013 at 03:25 AM. Reason: Added code tags and corrected indentation

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Trouble with creating new worksheets using cell values with multiple loop conditions

    Hi johnygaddar

    Welcome to the Forum!!

    First thing...you'll need to add Code Tags to you Code in Post #1

    To do so, Edit your post, highlight the Code, Click the Pound Sign (#) Button in the Ribbon above...click Save Changes.

    Second thing...pictures are of little value...

    Please attach a sample file that represents what you have. The structure of your attachment should be the same structure as your actual data. Any proprietary information should be changed.

    Include in the attachment any code you're currently using (whether it works or not) and an "After" worksheet that demonstrates what you wish the output to be.

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the "Add Files"... button to locate your file for uploading.
    6. This will open a new window File Upload...Click "Select Files"
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the "Upload Files" button and wait until the file has uploaded.
    10. Click the "Done" Button.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,719

    Re: Trouble with creating new worksheets using cell values with multiple loop conditions

    Welcome to the Forum!

    As jaslake has noted, we require code tags. Please take the time to review our rules. There aren't many, and they are all important.
    Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    Because this is your first post I took the liberty of adding code tags for you. The reason that code tags are required is that is preserves the indentation of your code. Therefore I also took the liberty of enhancing your indentation. When you see the indentation in your revised post, you will immediately see the problem, which is why indentation and code tags are important. You have an extra Next r and Next i inside your If. A Next statement has to match with its corresponding For statement at the same level within the code.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    10-01-2013
    Location
    India
    MS-Off Ver
    Excel 2007 & Excel 2010
    Posts
    7

    Re: Trouble with creating new worksheets using cell values with multiple loop conditions

    Hi John & Jeff

    Thanks for your help and suggestions, I have done the changes as suggested and will keep these in mind before posting new threads.

    I tried my macro again by removing extra NEXT r and Next i but stll its not working.

    Awaiting replies from you..

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,719

    Re: Trouble with creating new worksheets using cell values with multiple loop conditions

    Your attached file has no code in it.

    The lines of code you removed were actually correct; the ones that are left are the ones that should have been removed. However, that is just for the compile issue. Looking at your data and your description, the code has many problems and needed an overhaul. I made the changes and tested it with your file; I didn't repost the file.

    Note: When you change code after people have responded to your post, please do not edit the post, create a new post with the updated code. Now your original code is lost. That's a moot point here but something to remember for next time.

    This code should go in the module for sheet MACRO.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-01-2013
    Location
    India
    MS-Off Ver
    Excel 2007 & Excel 2010
    Posts
    7

    Re: Trouble with creating new worksheets using cell values with multiple loop conditions

    Hi

    I tried your quote but its getting struck
    Please Login or Register  to view this content.
    .
    Anyhow, I added some changes after which its working perfectly.

    Thanks once again for your help

+ 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. Replies: 1
    Last Post: 10-01-2013, 02:41 AM
  2. [SOLVED] Creating a VBA loop to search for values, stop when a cell value is 0
    By jfgay in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-30-2013, 10:30 AM
  3. [SOLVED] trouble with multiple values stacked in a cell using Alt+Enter - who needs a challenge?
    By sheriberi in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-22-2012, 03:45 PM
  4. [SOLVED] Macro to loop through cell values in a column and format multiple cell values
    By Roop in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-07-2012, 05:39 PM
  5. Creating worksheets from cell values
    By troth in forum Excel General
    Replies: 13
    Last Post: 07-20-2010, 02:13 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