+ Reply to Thread
Results 1 to 2 of 2

Error handling within a Do Loop

Hybrid View

Boondoggler Error handling within a Do... 04-30-2012, 10:43 PM
Sa DQ Re: Hope this help! 05-01-2012, 12:15 AM
  1. #1
    Registered User
    Join Date
    04-30-2012
    Location
    Huntington Beach, Ca
    MS-Off Ver
    Excel 2003
    Posts
    1

    Unhappy Error handling within a Do Loop

    I'm comparing two list of numbers on two different sheets to see which numbers have been omitted from one of the lists. I'm trying to use a Find statement with error trapping within a Do Loop to capture the missing numbers within a text string. The code works fine for detecting and capturing the first missing number, but when the second error occurs I just get the "Object variable or With block variable not set (Error 91)" error message. Is there something I have to do to "reset" the error handling? I tried err.clear but that doesn't seem to work. My code is below...

    Sub EDTankNoCompare()
    Dim TankNo As String
    Dim EDTankList As String
    Dim counter1 As Integer
    Dim counter2 As Integer
    TankList = ""
    Sheets("End Day").Select
    Range("A6").Select
    Do Until ActiveCell.Value = ""
        Do Until ActiveCell.Value = ""
            TankNo = ActiveCell.Text
            Sheets("Start Day").Select
            Columns("A:A").Select
            On Error GoTo ErrorHandler
            Selection.Find(What:=TankNo, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
                :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
                False, SearchFormat:=False).Activate
            Sheets("End Day").Select
            ActiveCell.Offset(1, 0).Select
        Loop
        Exit Sub
    ErrorHandler:
        Select Case Err.Number
            Case 91
                Sheets("End Day").Select
                TankList = EDTankList & ActiveCell.Text & ", "
                ActiveCell.Offset(1, 0).Select
                Err.Clear
            Case Else
                Resume
        End Select
    Loop
    End Sub
    Last edited by arlu1201; 05-01-2012 at 02:31 AM. Reason: Put code tags in future.

  2. #2
    Forum Contributor
    Join Date
    03-21-2012
    Location
    Ho Chi Minh city
    MS-Off Ver
    Excel 2003
    Posts
    180

    Re: Hope this help!

    PHP Code: 
    Option Explicit
    Sub ComperingColumnsInSheets
    ()
     
    Dim Sh As WorksheetRng As RangesRng As RangeCls As Range
     
     Set Sh 
    ThisWorkbook.Worksheets("End Day")     '<=|'
     
    Set Rng Sh.Range(Sh.[a6], Sh.[a6].End(xlDown))
     
    Sheets("Start Day").Select
     
    For Each Cls In Range([a2], [a2].End(xlDown))     '<=|'
        
    Set sRng Rng.Find(Cls.Value, , xlFormulasxlWhole)
        If 
    sRng Is Nothing Then
            Cls
    .Offset(, 4).Value "Nothing"
        
    Else
            
    Cls.Offset(, 4).Value "Row: " sRng.Row
        End 
    If
     
    Next Cls
    End Sub 

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1