我有一个基于数据范围创建工作表的宏,它工作得很好:
Sub AddSheetsFromCells()
Dim xRg As Range, wBk As Workbook
Set wBk = ActiveWorkbook
On Error GoTo Quit
Set dbRange = Application.InputBox("Range: ", "Select Range", _
Application.Selection.Address, Type:=8)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each xRg In dbRange
With wBk
.Sheets.Add After:=.Sheets(.Sheets.Count)
On Error Resume Next
ActiveSheet.Name = xRg.Value
If Err.Number = 1004 Then
Debug.Print Chr(34) & xRg.Value & Chr(34) & " already used as a sheet name"
.ActiveSheet.Delete
End If
On Error GoTo 0
End With
Next xRg
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Quit:
End Sub
这些创建的工作表是否可能包含与模板选项卡中相同的内容?
发布于 2021-02-04 12:06:45
而不是.Sheets.Add
,试试这个:
.Sheets("Template").Copy After:=.Sheets(.Sheets.Count)
如果有效,请让我们知道
https://stackoverflow.com/questions/66044980
复制