0

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

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • [Click here](https://stackoverflow.com/questions/6838437/how-to-check-whether-certain-sheets-exist-or-not-in-excel-vba) Hope the answer on this link helps – Cpt Kitkat Jan 30 '19 at 06:13
  • @saad , Thank You. It helped me. – Sravani Jan 30 '19 at 06:57
  • Possible duplicate of [How to check whether certain sheets exist or not in Excel-VBA?](https://stackoverflow.com/questions/6838437/how-to-check-whether-certain-sheets-exist-or-not-in-excel-vba) – shahkalpesh Apr 26 '19 at 10:31
  • Possible duplicate of [Test or check if sheet exists](https://stackoverflow.com/questions/6688131/test-or-check-if-sheet-exists) – Slai Apr 26 '19 at 11:00

0 Answers0