![](/img/trans.png)
[英]Trying to copy Range from worksheet into a new workbook. Excel VBA
[英]Excel VBA Trying to create a new worksheet
我想創建一個新的工作表,然后可以按單元格將數據添加到單元格中。 我已經嘗試過Sheets.Add.Name,但是它沒有用。 當前,我收到運行時錯誤“ 13”,感謝所有幫助。
ws.Name =“ Sheet1”在這種情況下。
Dim mySheet As Worksheet
j = -1
i = 0
strCounter = 0
For Each ws In ThisWorkbook.Worksheets
If (InStr(ws.Name, " Logix Friendly") = 0) Then
ifChecker = True
Else
ifChecker = False
End If
If ifChecker Then
Set mySheet = Workbooks.Add
With mySheet
.Nasme = ws.Name, " Logix Friendly"
End With
蒂姆·威廉姆斯(Tim Williams)添加新工作表是絕對正確的。
但是,您的邏輯似乎有缺陷。 僅當沒有名為“ Logix Friendly”的工作表且工作簿中只有1個工作表時,您的代碼才有效。
您應該做什么:
For Each ws In ThisWorkbook.Worksheets
bWS_Found = (InStr(1, ws.Name, "Logix Friendly", vbTextCompare) = 1)
' Exit checking if a worksheet already named "Logix Friendly"
If bWS_Found Then Exit For
Next
' Add worksheet if there isn't a "Logix Friendly" worksheet
If Not bWS_Found Then
With ThisWorkbook.Worksheets.Add
.Name = "Logix Friendly"
End With
End With
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.