我有一个工作簿,其中有两个工作表,我将它们复制到工作簿的末尾。
我尝试通过InputBox给这两个工作表命名为相同的名称,并为它们提供两个不同的后缀作为标准,第一个后缀是"xxx -项目“,下一个后缀是"xxx - Report”。
我已经将这两个工作表放在一个数组中。如何通过InputBox引用这两个工作表?
Public Sub CopySheets()
Dim shName As String 'Sheet name var
Dim shExists As Boolean
Do
shName = InputBox("Please enter name of new project", "New Project")
If shName <> "" Then
shExists = SheetExists(shName) 'Check for existing sheet name
If Not shExists Then
Worksheets(Array(1, 2)).Copy After:=Sheets(Sheets.Count)
Else
MsgBox "Project Name:" & Space(1) & shName & " already exists", vbOKOnly + vbCritical, "Deter"
End If
End If
Loop Until Not shExists Or shName = ""
End Sub
Private Function SheetExists(ByVal sheetName As String, _
Optional ByVal wb As Workbook)
If wb Is Nothing Then Set wb = ActiveWorkbook
On Error Resume Next
SheetExists = Not wb.Worksheets(sheetName) Is Nothing
End Function示例图像:

发布于 2020-02-19 22:52:27
在if conditon中类似的东西
If Not shExists Then
Worksheets(Array(1, 2)).Copy After:=Sheets(Sheets.Count)
Dim ws As Worksheet
Set ws = Sheets(Sheets.Count - 1)
ws.Name = shName & "- project"
Set ws = Sheets(Sheets.Count)
ws.Name = shName & "- report"
Elsehttps://stackoverflow.com/questions/60302699
复制相似问题