PDA

View Full Version : Solved: Another 'Else without If' error!



AKK
06-24-2009, 09:21 AM
Hi all,

Working on a different macro now, but still getting the same 'Else without If' error (and I do have the 'End If' in there now). Am I missing something else equally obvious?

Thanks!



Sub OverdueCategories()

Dim dCurrentDate As Date
Dim iDaysOverdue As Integer

dCurrentDate = InputBox("Enter current date")
iDaysOverdue = dCurrentDate - Selection.Offset(0, 3)

Range("F4").Select

Do Until Selection.Value = ""

If Selection.Value = "Open" And iDaysOverdue > 90 Then Selection.Value = "Over 90 days overdue"
ElseIf Selection.Value = "Open" And iDaysOverdue > 60 Then Selection.Value = "Over 60 days overdue"
ElseIf Selection.Value = "Open" And iDaysOverdue > 30 Then Selection.Value = "Over 30 days overdue"
ElseIf Selection.Value = "Open" And iDaysOverdue <= 30 Then Selection.Value = "30 days overdue or less"
Else: Selection.Offset(1, 0).Select
End If

Loop

End Sub

tpoynton
06-24-2009, 09:31 AM
try
If Selection.Value = "Open" And iDaysOverdue > 90 Then
Selection.Value = "Over 90 days overdue"
ElseIf Selection.Value = "Open" And iDaysOverdue > 60 Then
Selection.Value = "Over 60 days overdue"
ElseIf Selection.Value = "Open" And iDaysOverdue > 30 Then
Selection.Value = "Over 30 days overdue"
ElseIf Selection.Value = "Open" And iDaysOverdue <= 30 Then
Selection.Value = "30 days overdue or less"
Else
Selection.Offset(1, 0).Select
End If

CreganTur
06-24-2009, 09:44 AM
If statements are very strict when it comes to formatting. When you put the If, Conditional, and Result all on the same line, VBA reads it as a strict, in-line If statement.

These kinds of If statements do not allow for ElseIF or Else conditionals. You have to break it up over multiple lines if you want to use ElseIf or Else conditional statements as a part of the same If.

HTH:thumb

AKK
06-24-2009, 09:52 AM
Figured it out.