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
Bookmarks