我的excel工作簿工作表以日期命名(“ DD-MMM-YYYY”),我必须将每张工作表中的数据输入另一个excel。当我使用循环(从日期到日期)时,该工作表不可用的日期阻碍了我的脚本。VBA中是否存在不存在的东西?
Sub gettheTips()
Dim fromDate As Date
Dim toDate As Date
fromDate = InputBox("Enter the From date for the tips")
toDate = InputBox("Enter the To date for the tips")
'Ensure that from date less than the to date
If (fromDate < toDate) Then
'Select all the tips from date todate
For i = fromDate To toDate
dt = Format(i, "d-mmm-yyyy")
'MsgBox (dt)
'copy paste the tips from all the days to the Report sheet
If Worksheet(dt <> "") Then
Sheets(dt).Select
Range("E9").Select
Selection.Copy
Sheets("Report").Select
Range("E17").Select
ActiveSheet.Paste
Else
MsgBox ("The worksheet named" & dt & "does not exists")
End If
Next
Else
MsgBox ("From Date is greater than the todate entered")
End Sub
当工作簿中没有日期工作表时,我希望代码不显示名为“”的消息框工作表