我試圖創建從sheet1
細胞攝取名工作表設置名稱,但在執行Worksheets(Worksheets.Count).name = companyName
1004錯誤時,試圖對XLS工作
時,我總是得到一個1004 error
我嘗試設置表由PrefferedName
命名和工作......我也有MsgBox
是companyName
變量檢查有最後一張紙的名稱...
Sub Find2()
Dim i, k As Integer
Dim j, l As Integer
Dim Counter As Integer
Dim dateAnnounced As Date
Dim fromDate As Date
Dim currentCellDate As Date
Dim daysBefore As Integer
Dim kk As Integer
Dim from1 As Integer
Dim companyName As Variant
Set originsheet = ThisWorkbook.Worksheets("Sheet1")
daysBefore = 30
i = 3
j = 4
Counter = 0
k = 5
l = 4179
dateAnnounced = Cells(i, j).Value
For Each cel In Range(Cells(1, k), Cells(1, 4179))
currentCellDate = cel.Value
If currentCellDate = dateAnnounced Then
MsgBox k
Exit For
End If
k = k + 1
Next cel
kk = k
from1 = k - daysBefore
ThisWorkbook.Sheets.Add after:=Sheets(Worksheets.Count)
companyName = Worksheets("Sheet1").Cells(i, j - 1).Value
Worksheets(Worksheets.Count).name = companyName
MsgBox name
For Each cel In Range(Cells(1, from1), Cells(1, kk))
If from1 = kk Then
MsgBox cel.Value
Exit For
Else
Counter = Counter + 1
End If
from1 = from1 - 1
Next cel
MsgBox Counter
End Sub
我不知道是什麼問題,但有一件事你應該做的是看跌期權在這個模塊的頂部明確。這迫使你在使用它們之前聲明所有的變量。您將看到「名稱」未被聲明爲變量,這將影響您的MsgBox語句之一。此外,雖然它不會影響您的代碼,但請注意,「Dim i,k As Integer」表示「Dim i As Variant,k As Integer」 –
您可以給我們公司名稱的值嗎?不超過31個字符,其中沒有「[]?* \ /」? – KekuSemau
Associated Group Inc是公司名稱,它沒有奇怪的字符.. – agagelis