Results 1 to 6 of 6

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

Threaded View

  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


    Public Sub Unnamed()
    
       Dim intRowCount As Integer
       
       Dim i As Integer
       
       intRowCount = Range("a1").CurrentRegion.Rows.Count
       rgnrowcount = Range("c1").CurrentRegion.Rows.Count
       
       Range("a2").Select
       For i = 2 To intRowCount
       
          Range("c2").Select
          For r = 2 To rngRowCount
          
             Sheets("MACRO").Select
             If Range("c" & i).Value = "Yes" Then
             
                Sheets.Add
                ActiveSheet.Select
                If ActiveSheet.Name <> "" Then ActiveSheet.Name = Sheets("MACRO").Range("a" & r)
          
                Next r
                Next i
          
             Else
             End If
          
       End Sub
    Attached Files Attached Files
    Last edited by johnygaddar; 10-02-2013 at 03:25 AM. Reason: Added code tags and corrected indentation

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