Results 1 to 1 of 1

Copy Template, nename tabs based on column entry; need help to stop macro at blank cell

Threaded View

  1. #1
    Registered User
    Join Date
    07-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    37

    Smile Copy Template, nename tabs based on column entry; need help to stop macro at blank cell

    Inventory Report - Test.xlsm

    I'm having difficulty with the following:

    Writing a macro that copies a template labeled "Master" based on inputs from cells on a worksheet labeled "Locations" (cells a1:a39) and renames the tabs and labels the worksheets based on the same entries from the cells on the "Locations" entries. The macro does all of the above, however it generates a "Master (2)" tab and generates a run-time error '1004': Application-defined or object-defined error for the macro line in red (below). There is also a command button on the "Locations" tab to execute the macro. I've attached a copy of the workbook.

    1) I need help crafting a macro that skips blank cells or terminates after reaching a blank cell on the "Locations" tab (cells a1:a39).

    2) Also, is it possible to hide the "Master" tab, but still have the macro make visible copies of the worksheet?

    Any assistance would be greatly appreciated.


    Sub addsheetsandname()
         
        If Sheet2.Range("A1").Value = Empty Then
            MsgBox "  Please Enter Depot Name"
        Exit Sub
        End If
        
        Dim i As Integer
        Dim cell As Variant
        Dim wks As Worksheet
            
            Set wks = Sheets("Locations")
            
            For i = 1 To 39
        
        Sheets("Master").Copy After:=wks
            ActiveSheet.Name = wks.Cells(i, 1).Value
            ActiveSheet.Cells(5, 2) = wks.Cells(i, 1)
         
        Sheets("Locations").Activate
            For Each cell In Range("A1:A39" & Cells(Rows.Count, "A").End(xlUp).Row)
        If Len(cell.Value) = 0 Then Exit For
                          
        Next
        Next
        
    End Sub
    Last edited by gophil1; 07-26-2012 at 12:27 AM. Reason: Forgot to code the macro prior to posting.

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