Microsoft Excel 2007
Windows XP
My code works fine for creating the first 10 sheets but then stops. I'm not sure if that means I am copy-pasting too much for the document to handle or what.
In module1:
Private Sub Button1_click()
Call Device1
Call Device2
Call Device3
Call Device4
Call Device5
Call Device6
Call Device7
Call Device8
Call Device9
Call Device10
Call Device11
Call Device12
Call Device13
Call Device14
Call Device15
Call Device16
Call Device17
Call Device18
Call Device19
Call Device20
Call Device21
Call Device22
Call Device23
Call Device24
Call Device25
Call Device26
Call Device27
Call Device28
Call Device29
Call Device30
Call Device31
Call Device32
Call Device33
Call Device34
Call Device35
Call Device36
Call Device37
Call Device38
Call Device39
Call Device40
Call Device41
Call Device42
Call Device43
Call Device44
Call Device45
Call Device46
Call Device47
Call Device48
Call Device49
Call Device50
Call Device51
Call Device52
Call Device53
Call Device54
Call Device55
Call Device56
Call Device57
Call Device58
Call Device59
Call Device60
End Sub
Sub Device1()
If Not ActiveSheet.Range("D14").Value = "" Then
'begin add new sheet
'From http://www.mrexcel.com/archive/VBA/1869.html
Sheets("MS77").Select
Dim MS77 As String
Dim ActNm As String
With ActiveSheet
MS77 = .Name
End With
On Error Resume Next
Sheets("MS77").Name = Sheets("Checklist").Range("B14") & Sheets("Checklist").Range("C14") & Sheets("Checklist").Range("D14")
If Err.Number = 1004 Then ActiveSheet.Name = InputBox("Give name.")
If ActiveSheet.Name = ActNm Then GoTo NoName
On Error GoTo 0
With ActiveWorkbook.Sheets
.Add after:=Worksheets(Worksheets.Count)
End With
ActNm = ActiveSheet.Name
On Error Resume Next
ActiveSheet.Name = "MS77"
NoName: If Err.Number = 1004 Then ActiveSheet.Name = InputBox("Give name.")
If ActiveSheet.Name = ActNm Then GoTo NoName
On Error GoTo 0
'end add new sheet
'change new sheet column sizes
ActiveSheet.Columns("A:D").ColumnWidth = 2
ActiveSheet.Columns("E:E").ColumnWidth = 15
ActiveSheet.Columns("F:F").ColumnWidth = 34.86
ActiveSheet.Columns("G:G").ColumnWidth = 43
ActiveSheet.Columns("H:H").ColumnWidth = 15
'end change sizes
'begin copy over MS77 form
Worksheets(ActiveSheet.Index - 1).Select
ActiveSheet.Range("B2:H23").Select
Selection.Copy
Worksheets(ActiveSheet.Index + 1).Select
ActiveSheet.Range("B2").Select
ActiveSheet.Paste
ActiveSheet.Range("B9:D23").HorizontalAlignment = xlCenter
'end copy over MS77 form
The code goes on to include If-then statements on what else should be put in that B2:H23 region. The sub ends and Device 2 begins with the exact same code except for the next row down on the reference sheet "Checklist."
Here is the difference between Sub Device10 and Sub Device11:
Sub Device10()
If Not ActiveSheet.Range("D23").Value = "" Then
'-----------------------------^^^^-(change to the current row)
'begin add new sheet
'From http://www.mrexcel.com/archive/VBA/1869.html
Sheets("MS77").Select
With ActiveSheet
MS77 = .Name
End With
On Error Resume Next
Sheets("MS77").Name = Sheets("Checklist").Range("B23") & Sheets("Checklist").Range("C23") & Sheets("Checklist").Range("D23")
'----------------------------------------------------^^^^-------------------------------^^^^-------------------------------^^^^
If Err.Number = 1004 Then ActiveSheet.Name = InputBox("Give name.")
If ActiveSheet.Name = ActNm Then GoTo NoName
On Error GoTo 0
With ActiveWorkbook.Sheets
.Add after:=Worksheets(Worksheets.Count)
End With
ActNm = ActiveSheet.Name
On Error Resume Next
ActiveSheet.Name = "MS77"
NoName: If Err.Number = 1004 Then ActiveSheet.Name = InputBox("Give name.")
If ActiveSheet.Name = ActNm Then GoTo NoName
On Error GoTo 0
'THERE IS MORE CODE HERE but it is irrelevant to creating new sheets
End Sub
Sub Device11()
If Not ActiveSheet.Range("D24").Value = "" Then
'-----------------------------^^^^-(change to the current row)
'begin add new sheet
'From http://www.mrexcel.com/archive/VBA/1869.html
Sheets("MS77").Select
With ActiveSheet
MS77 = .Name
End With
On Error Resume Next
Sheets("MS77").Name = Sheets("Checklist").Range("B24") & Sheets("Checklist").Range("C24") & Sheets("Checklist").Range("D24")
'----------------------------------------------------^^^^-------------------------------^^^^-------------------------------^^^^
If Err.Number = 1004 Then ActiveSheet.Name = InputBox("Give name.")
If ActiveSheet.Name = ActNm Then GoTo NoName
On Error GoTo 0
With ActiveWorkbook.Sheets
.Add after:=Worksheets(Worksheets.Count)
End With
ActNm = ActiveSheet.Name
On Error Resume Next
ActiveSheet.Name = "MS77"
NoName: If Err.Number = 1004 Then ActiveSheet.Name = InputBox("Give name.")
If ActiveSheet.Name = ActNm Then GoTo NoName
On Error GoTo 0
'THERE IS MORE CODE HERE but it is irrelevant to creating new sheets
End Sub
Your help is much appreciated! If there is any additional info I can provide, let me know.
Windows XP
My code works fine for creating the first 10 sheets but then stops. I'm not sure if that means I am copy-pasting too much for the document to handle or what.
In module1:
Private Sub Button1_click()
Call Device1
Call Device2
Call Device3
Call Device4
Call Device5
Call Device6
Call Device7
Call Device8
Call Device9
Call Device10
Call Device11
Call Device12
Call Device13
Call Device14
Call Device15
Call Device16
Call Device17
Call Device18
Call Device19
Call Device20
Call Device21
Call Device22
Call Device23
Call Device24
Call Device25
Call Device26
Call Device27
Call Device28
Call Device29
Call Device30
Call Device31
Call Device32
Call Device33
Call Device34
Call Device35
Call Device36
Call Device37
Call Device38
Call Device39
Call Device40
Call Device41
Call Device42
Call Device43
Call Device44
Call Device45
Call Device46
Call Device47
Call Device48
Call Device49
Call Device50
Call Device51
Call Device52
Call Device53
Call Device54
Call Device55
Call Device56
Call Device57
Call Device58
Call Device59
Call Device60
End Sub
Sub Device1()
If Not ActiveSheet.Range("D14").Value = "" Then
'begin add new sheet
'From http://www.mrexcel.com/archive/VBA/1869.html
Sheets("MS77").Select
Dim MS77 As String
Dim ActNm As String
With ActiveSheet
MS77 = .Name
End With
On Error Resume Next
Sheets("MS77").Name = Sheets("Checklist").Range("B14") & Sheets("Checklist").Range("C14") & Sheets("Checklist").Range("D14")
If Err.Number = 1004 Then ActiveSheet.Name = InputBox("Give name.")
If ActiveSheet.Name = ActNm Then GoTo NoName
On Error GoTo 0
With ActiveWorkbook.Sheets
.Add after:=Worksheets(Worksheets.Count)
End With
ActNm = ActiveSheet.Name
On Error Resume Next
ActiveSheet.Name = "MS77"
NoName: If Err.Number = 1004 Then ActiveSheet.Name = InputBox("Give name.")
If ActiveSheet.Name = ActNm Then GoTo NoName
On Error GoTo 0
'end add new sheet
'change new sheet column sizes
ActiveSheet.Columns("A:D").ColumnWidth = 2
ActiveSheet.Columns("E:E").ColumnWidth = 15
ActiveSheet.Columns("F:F").ColumnWidth = 34.86
ActiveSheet.Columns("G:G").ColumnWidth = 43
ActiveSheet.Columns("H:H").ColumnWidth = 15
'end change sizes
'begin copy over MS77 form
Worksheets(ActiveSheet.Index - 1).Select
ActiveSheet.Range("B2:H23").Select
Selection.Copy
Worksheets(ActiveSheet.Index + 1).Select
ActiveSheet.Range("B2").Select
ActiveSheet.Paste
ActiveSheet.Range("B9:D23").HorizontalAlignment = xlCenter
'end copy over MS77 form
The code goes on to include If-then statements on what else should be put in that B2:H23 region. The sub ends and Device 2 begins with the exact same code except for the next row down on the reference sheet "Checklist."
Here is the difference between Sub Device10 and Sub Device11:
Sub Device10()
If Not ActiveSheet.Range("D23").Value = "" Then
'-----------------------------^^^^-(change to the current row)
'begin add new sheet
'From http://www.mrexcel.com/archive/VBA/1869.html
Sheets("MS77").Select
With ActiveSheet
MS77 = .Name
End With
On Error Resume Next
Sheets("MS77").Name = Sheets("Checklist").Range("B23") & Sheets("Checklist").Range("C23") & Sheets("Checklist").Range("D23")
'----------------------------------------------------^^^^-------------------------------^^^^-------------------------------^^^^
If Err.Number = 1004 Then ActiveSheet.Name = InputBox("Give name.")
If ActiveSheet.Name = ActNm Then GoTo NoName
On Error GoTo 0
With ActiveWorkbook.Sheets
.Add after:=Worksheets(Worksheets.Count)
End With
ActNm = ActiveSheet.Name
On Error Resume Next
ActiveSheet.Name = "MS77"
NoName: If Err.Number = 1004 Then ActiveSheet.Name = InputBox("Give name.")
If ActiveSheet.Name = ActNm Then GoTo NoName
On Error GoTo 0
'THERE IS MORE CODE HERE but it is irrelevant to creating new sheets
End Sub
Sub Device11()
If Not ActiveSheet.Range("D24").Value = "" Then
'-----------------------------^^^^-(change to the current row)
'begin add new sheet
'From http://www.mrexcel.com/archive/VBA/1869.html
Sheets("MS77").Select
With ActiveSheet
MS77 = .Name
End With
On Error Resume Next
Sheets("MS77").Name = Sheets("Checklist").Range("B24") & Sheets("Checklist").Range("C24") & Sheets("Checklist").Range("D24")
'----------------------------------------------------^^^^-------------------------------^^^^-------------------------------^^^^
If Err.Number = 1004 Then ActiveSheet.Name = InputBox("Give name.")
If ActiveSheet.Name = ActNm Then GoTo NoName
On Error GoTo 0
With ActiveWorkbook.Sheets
.Add after:=Worksheets(Worksheets.Count)
End With
ActNm = ActiveSheet.Name
On Error Resume Next
ActiveSheet.Name = "MS77"
NoName: If Err.Number = 1004 Then ActiveSheet.Name = InputBox("Give name.")
If ActiveSheet.Name = ActNm Then GoTo NoName
On Error GoTo 0
'THERE IS MORE CODE HERE but it is irrelevant to creating new sheets
End Sub
Your help is much appreciated! If there is any additional info I can provide, let me know.