我正在尝试创建名称取自单元格的工作表,但在执行时 sheet1
我总是得到一个1004 error
Worksheets(Worksheets.Count).name = companyName
我尝试设置工作表名称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