Error handling

hemant86

New Member
Joined
Feb 10, 2015
Messages
32
Hi Folks,

I'm trying to use the below code:
Rich (BB 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 a moderator:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,214,522
Messages
6,120,020
Members
448,939
Latest member
Leon Leenders

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top