My VBA have this run time error 91 on the line below that underline with red color.
My MRStart1 didn't found anythings and jump to MBranch2: but if my MRStart2 didn't found anythings then the error 91 come out.
What is the problem guys?
If ThisWorkbook.Sheets("DATABASE").Range("D2").Value > 0 Then
On Error GoTo MBranch2
Dim MRStart1 As Range, MREnd1 As Range
Set MRStart1 = Columns("A").Find(What:=ThisWorkbook.Sheets("DATABASE").Range("D2").Value, LookIn:=xlValues, LookAt:=xlWhole).Offset(1)
Set MREnd1 = Columns("A").Find(What:="Total Sales For ", After:=MRStart1, LookIn:=xlValues, LookAt:=xlWhole).Offset(-1)
Range(MRStart1, MREnd1).Select
Selection.Value = ThisWorkbook.Sheets("DATABASE").Range("D2").Value
End If
MBranch2:
If ThisWorkbook.Sheets("DATABASE").Range("D3").Value > 0 Then
On Error GoTo MBranch3
Dim MRStart2 As Range, MREnd2 As Range
Set MRStart2 = Columns("A").Find(What:=ThisWorkbook.Sheets("DATABASE").Range("D3").Value, LookIn:=xlValues, LookAt:=xlWhole).Offset(1)
Set MREnd2 = Columns("A").Find(What:="Total Sales For ", After:=MRStart2, LookIn:=xlValues, LookAt:=xlWhole).Offset(-1)
Range(MRStart2, MREnd2).Select
Selection.Value = ThisWorkbook.Sheets("DATABASE").Range("D3").Value
End If
MBranch3:
My MRStart1 didn't found anythings and jump to MBranch2: but if my MRStart2 didn't found anythings then the error 91 come out.
What is the problem guys?
If ThisWorkbook.Sheets("DATABASE").Range("D2").Value > 0 Then
On Error GoTo MBranch2
Dim MRStart1 As Range, MREnd1 As Range
Set MRStart1 = Columns("A").Find(What:=ThisWorkbook.Sheets("DATABASE").Range("D2").Value, LookIn:=xlValues, LookAt:=xlWhole).Offset(1)
Set MREnd1 = Columns("A").Find(What:="Total Sales For ", After:=MRStart1, LookIn:=xlValues, LookAt:=xlWhole).Offset(-1)
Range(MRStart1, MREnd1).Select
Selection.Value = ThisWorkbook.Sheets("DATABASE").Range("D2").Value
End If
MBranch2:
If ThisWorkbook.Sheets("DATABASE").Range("D3").Value > 0 Then
On Error GoTo MBranch3
Dim MRStart2 As Range, MREnd2 As Range
Set MRStart2 = Columns("A").Find(What:=ThisWorkbook.Sheets("DATABASE").Range("D3").Value, LookIn:=xlValues, LookAt:=xlWhole).Offset(1)
Set MREnd2 = Columns("A").Find(What:="Total Sales For ", After:=MRStart2, LookIn:=xlValues, LookAt:=xlWhole).Offset(-1)
Range(MRStart2, MREnd2).Select
Selection.Value = ThisWorkbook.Sheets("DATABASE").Range("D3").Value
End If
MBranch3: