Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Error handling

  1. #1
    New Member
    Join Date
    Feb 2015
    Posts
    29
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Error handling

    Hi Folks,

    I'm trying to use the below code:
    Code:
    sub main()
    .....
    .....
    Windows(e).Activate
        Columns("A:A").Select
        Selection.ClearContents
    
        Windows(n).Activate
        lRow = Range("AD" & Rows.Count).End(xlUp).Row
        Range("AD2:AD" & lRow).Copy
        Windows(e).Activate
        Range("A1").PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
        
    On Error GoTo NextStep3
        Selection.SpecialCells(xlCellTypeBlanks).Select
        Selection.Delete Shift:=xlUp
        
       
    NextStep3:
        iRow = 0
        While Sheets(1).Cells(iRow + 1, 1) <> ""
            Criteria_Val(iRow) = Sheets(1).Cells(iRow + 1, 1)
            iRow = iRow + 1
        Wend
        
        Workbooks("Reference Data").Sheets("OSPD CC List").Range("A1:X1").AutoFilter Field:=3, Criteria1:=Criteria_Val, Operator:=xlFilterValues
        Windows(k).Activate
        Sheets("OSPD CC List").Activate
        Lrow1 = Range("C" & Rows.Count).End(xlUp).Row
        
        Set qRng = Range("Q1:Q" & Lrow1)
        Set sRng = Range("S1:S" & Lrow1)
        
        
        Set uRng = Union(qRng, sRng)
        uRng.Copy
        
        Windows(n).Activate
        
        Range("BQ1").Select
        ActiveSheet.Paste
        
        Windows(k).Activate
        Selection.AutoFilter
    End Sub
    I'm getting runtime error in "Selection.SpecialCells(xlCellTypeBlanks).Select" step which is normal but I have also used Error handler to skip this step.
    For some reason error handler is not behaving the same way it should.Its not going to the NextStep3: . But here is the catch...i have used error handler twice more in the same module
    before this code and it's working fine. And when I'm trying to run the above code in a different module also it works fine.

    Any assistance would be appriciated.

    Thanks
    Last edited by RoryA; Mar 10th, 2016 at 09:40 AM.

  2. #2
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    32,351
    Post Thanks / Like
    Mentioned
    25 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Error handling

    Quote Originally Posted by hemant86 View Post
    But here is the catch...i have used error handler twice more in the same module
    before this code and it's working fine.
    That suggests you haven't reset the exception. Please read this: On Error WTF? | Excel Matters

  3. #3
    New Member
    Join Date
    Feb 2015
    Posts
    29
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Error handling

    Thanks for the quick reply Rory. That solved my problem.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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