セルから取得した名前でワークシートを作成しようとしていますが、実行時に 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