0

This is a for loop code that goes through nested ifs. This code shows "Compile error: Else without If" but there is If matching for each Else. Please help me finding out what's causing the error!

Sub Clearing()

Dim BR As Excel.Workbook
Dim t As Integer
Dim b As Integer
Dim Found As Range
Dim Cldate As Date

Set BR = Workbooks("BankRec.xlsm")
Cldate = Application.InputBox("Enter the clearing date in MM/DD/YYYY format")
t = BR.Worksheets("aaaa").Cells(1, 1).End(xlDown).Row
b = BR.Worksheets("aaaa").Cells(Rows.Count, 1).End(xlUp).Row


For i = t To b
BR.Worksheets("aaaa").Cells(t + 1, 10).Select
If IsEmpty(BR.Worksheets("aaaa").Cells(t + 1, 10).Value) = True Then

    With BR.Worksheets("aaaa").Range(BR.Worksheets("aaaa").Cells(t + 2, 9), BR.Worksheets("aaaa").Cells(b, 9))
    Set Found = .Find(what:=BR.Worksheets("aaaa").Cells(t + 1, 9).Value * -1)


    If Found.Offset(0, -2).Value = BR.Worksheets("aaaa").Cells(t + 1, 7).Value And Found.Offset(0, 2).Value = BR.Worksheets("aaaa").Cells(t + 1, 11).Value Then
    BR.Worksheets("aaaa").Cells(t + 1, 10).Value = Cldate & " " & t
Found.Offset(0, 1).Value = Cldate & " " & t
    Else
    End If

Else
End If

t = t + 1

Next i

MsgBox "Clearing complete!"

End Sub
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Bonnie J
  • 3
  • 3
  • 4
    you need to match up that `with` with and `end with` – Marcucciboy2 Nov 07 '19 at 01:56
  • 1
    You might benefit from reading [How to avoid using Select in Excel VBA](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba). • Also indent your code correctly and you will immediately see where you went wrong! Code formatting is abosutly helpful. Bad formatted code will result in errors. – Pᴇʜ Nov 07 '19 at 11:24

0 Answers0