On Error Goto Blue Does not work

Hashiru

Active Member
Joined
May 29, 2011
Messages
285
Hi everyone, I have these lines of codes:
Code:
FoundValue = MySheet.Cells.Find(What:="Deductions from Net Pay", After:=Cells(1, 1), LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Row

On Error Resume Next
FoundValue1 = MySheet.Cells.Find(What:="Additions to Net Pay", After:=Cells(1, 1), LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Row
RowNum4 = FoundValue
        
                On Error GoTo Blue
                Do Until MySheet.Cells(RowNum4, 2) = "Total Deductions from Net Pay"
        
        
                   RowNum4 = RowNum4 + 1
                   CellContent = MySheet.Cells(RowNum4, 3)
                   
                   If CellContent = "401(K) Loan Repay" Then '1
                        TransferSheet.Cells(NextRow, 45) = MySheet.Cells(RowNum4, ColNum + 4) * -1
                    Else
                   End If
                    If CellContent = "Moneys Owed  to Company" Then '2
                        TransferSheet.Cells(NextRow, 46) = MySheet.Cells(RowNum4, ColNum + 4) * -1
                    Else
                   End If
                Loop
       
Blue:
           
          rownum5 = FoundValue1
          
          
          On Error GoTo Green
                Do Until MySheet.Cells(rownum5, 2) = "Total Additions to Net Pay"
        
        
           
                   rownum5 = rownum5 + 1
                   CellContent = MySheet.Cells(rownum5, 3)
                   
                   If CellContent = "Reimburse-Educational Assist" Then '1
                        TransferSheet.Cells(NextRow, 47) = MySheet.Cells(rownum5, ColNum + 4) * -1
                    Else
                   End If
                    'If CellContent = "Moneys Owed  to Company" Then '2
                        'TransferSheet.Cells(NextRow, 46) = MySheet.Cells(RowNum5, ColNum + 4) * -1
                    'Else
                   'End If
                Loop
           
2:
Green:
The code is supposed to find two phrase and use those phrases in the Do Until Loop to transfer records if found otherwise I want the code to do nothing.

Thanks in advance.
 
Last edited by a moderator:

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,178
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,178
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
The recommended way is to check if the value is found like this:
Code:
Dim rgFound as Range
Set rgFound = MySheet.Cells.Find(What:="Deductions from Net Pay", After:=Cells(1, 1), LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)
If not rgFound Is nothing then 
   FoundValue = rgFound.Row
Else
   Exit Sub
End If
 

Forum statistics

Threads
1,078,252
Messages
5,339,097
Members
399,277
Latest member
Jyoti C

Some videos you may like

This Week's Hot Topics

Top