My excel workbook sheets are named with the dates("DD-MMM-YYYY") and I have to get the data from each sheet in to another excel. When i use for loop(from date to date), the date for which the sheet is not available is holding back my script.Do we have something called not exists in 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
I expect the code to display messagebox worksheet named "" doesnot exists when the dated sheet is not available in workbook