+ Reply to Thread
Results 1 to 10 of 10

Create multiple sheets in new workbook based on credentials in source workbook

Hybrid View

  1. #1
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Create multiple sheets in new workbook based on credentials in source workbook

    Let me look through your attachment and see how i can help you. The sheets in the new workbook have to be renamed with the Supplier Code right?
    Last edited by arlu1201; 10-07-2011 at 06:37 AM.

  2. #2
    Forum Contributor
    Join Date
    01-18-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    127

    Re: Create multiple sheets in new workbook based on credentials in source workbook

    Yes that's right. Thanks for your help so far. I'm thinking about 3 loops need to run. The first one to cycle through each row. Second to cycle through each column in that row. Third to cycle through all the sheet names in the new workbook created so far to see whether it already exists or not.

    One thing to note is that not all columns are populated. Some have more than one supplier code and some don't.

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Create multiple sheets in new workbook based on credentials in source workbook

    Yes i have done the same thing but facing some probs. Am working on them

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Create multiple sheets in new workbook based on credentials in source workbook

    I have created this code but its erroring out when i have a sheet with the same name, even though i have an error handler. Maybe someone can help us just modify this a lil bit and it should work for you.

    Sub check_code()
    
    Dim SheetName As String
    Dim ws As Worksheet
    On Error GoTo Errhandler
    
    Fname = ActiveWorkbook.Name
    Workbooks.Add
    
    MName = ActiveWorkbook.Name
    For i = 1 To Workbooks(Fname).Worksheets("Sheet1").Range("A2").End(xlToRight).Column Step 2
    
        For j = 3 To Workbooks(Fname).Worksheets("Sheet1").Cells(3, i).End(xlDown).Row
        
    resume_sheet:
            Workbooks(Fname).Worksheets(1).Activate
            SheetName = Workbooks(Fname).Worksheets("Sheet1").Cells(j, i).Text
            
            For Each ws In Workbooks(MName).Worksheets
                
                If SheetName = "" Or ws.Name = SheetName Then
                    
                    j = j + 1
                    GoTo stopcode
                
                Else
                            
                     Workbooks(Fname).Worksheets("Invoice_Sheet").Copy before:=Workbooks(MName).Sheets(1)
                     
                     If ws.Name = SheetName Then
                     
                        GoTo Errhandler
                    
                     Else
                     
                     Workbooks(MName).Worksheets("Invoice_Sheet").Name = SheetName
                     'GoTo stopcode
                     
                     End If
                     
                End If
                           
             'Next
             Next
    stopcode:
            Next
    
        Next
        
    Errhandler:
          MsgBox Err.Description
          Application.DisplayAlerts = False
          ActiveSheet.Delete
          Application.DisplayAlerts = True
          GoTo resume_sheet
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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