VBA WORKSHEET

COMPILE ERROR END IF WITHOUT BLOCK IF

Sub EnterDates()
Columns().Clear

Dim EilDownloadSheet As Worksheet
Set EilDownloadSheet = Workbook.Worksheets("Name of worksheet")


Dim startDate As String, stopDate As String, startCel As Integer, stopcel As Integer, dateRange As Range
On Error Resume Next

Do

startDate = InputBox("Please enter start Date: format (dd/mm/yy)", "Start Date")
If startDate = "" Then End
Loop Until startDate = Format(startDate, "dd/mm/yy") Or startDate = Format(startDate, "m/d/yy")


Dim blnCancel As Boolean
Dim blnValid As Boolean
blnCancel = False
blnValid = False

Do

startDate = InputBox("Please enter start Date: format (dd/mm/yy)", "Start Date")
If startDate = vbNullString Then
blnCancel = True
Else
If CDate(startDate) = False Then
blnValid = False
Else
blnValid = True
End If

Do
Loop Until blnValid = True Or blnCancel = True

End If
End If
End If

End Sub



Answer this question

VBA WORKSHEET

  • Brian Pos

    ok Thanks for your help
  • frrobi

    Well Im using excel 2003
  • J. Newman

    Hey

    I tried that then I get another error Do without Loop on the End Sub


  • Micromause

    good day!

    try deleting some end if's at the end of your code..

    ..........

    Do

    startDate = InputBox("Please enter start Date: format (dd/mm/yy)", "Start Date")
    If startDate = vbNullString Then
    blnCancel = True
    Else
    If CDate(startDate) = False Then
    blnValid = False
    Else
    blnValid = True
    End If
    End If


    Loop Until blnValid = True Or blnCancel = True


  • tkim11

    and maybe you mean Isdate.. not Cdate to check the validity of the date.

    ...........................

    Do

    startDate = InputBox("Please enter start Date: format (dd/mm/yy)", "Start Date")
    If startDate = vbNullString Then
    blnCancel = True
    Else
    If IsDate(startDate) = False Then
    blnValid = False
    Else
    blnValid = True
    End If
    End If


    Loop Until blnValid = True Or blnCancel = True


  • Koolchamp

    i try ur code here.. it works fine..

    but try Microsoft ISV Community Center Forums they discuss VBA there more..


  • Rob Daigneau

    Sub EnterDates()
    Columns().Clear

    Dim EilDownloadSheet As Worksheet
    Set EilDownloadSheet = Workbook.Worksheets("Name of worksheet")


    Dim startDate As String, stopDate As String, startCel As Integer, stopcel As Integer, dateRange As Range
    On Error Resume Next

    Do

    startDate = InputBox("Please enter start Date: format (dd/mm/yy)", "Start Date")
    If startDate = "" Then End
    Loop Until startDate = Format(startDate, "dd/mm/yy") Or startDate = Format(startDate, "m/d/yy")


    Dim blnCancel As Boolean
    Dim blnValid As Boolean
    blnCancel = False
    blnValid = False

    Do 'missing loop

    startDate = InputBox("Please enter start Date: format (dd/mm/yy)", "Start Date")
    If startDate = vbNullString Then
    blnCancel = True
    Else
    If CDate(startDate) = False Then 'should be IsDate()
    blnValid = False
    Else
    blnValid = True
    End If

    Do 'or is this one wrong
    Loop Until blnValid = True Or blnCancel = True

    End If
    End If 'missing if statement
    End If 'missing if statement

    End Sub

    hopefully that will fix your compile errors.



  • sherifsoft2002

    i tried this block of code in here.. it looks fine.. your using vb2005 right

    ' ===================

    Sub EnterDates()
    Columns().Clear()

    Dim EilDownloadSheet As Worksheet
    EilDownloadSheet = Workbook.Worksheets("Name of worksheet")


    Dim startDate As String, stopDate As String, startCel As Integer, stopcel As Integer, dateRange As Range
    On Error Resume Next

    Do

    startDate = InputBox("Please enter start Date: format (dd/mm/yy)", "Start Date")
    If startDate = "" Then End
    Loop Until startDate = Format(startDate, "dd/mm/yy") Or startDate = Format(startDate, "m/d/yy")


    Dim blnCancel As Boolean
    Dim blnValid As Boolean
    blnCancel = False
    blnValid = False

    Do

    startDate = InputBox("Please enter start Date: format (dd/mm/yy)", "Start Date")
    If startDate = vbNullString Then
    blnCancel = True
    Else
    If IsDate(startDate) = False Then
    blnValid = False
    Else
    blnValid = True
    End If
    End If


    Loop Until blnValid = True Or blnCancel = True

    ' ===================


  • VBA WORKSHEET