"Method 'Selection' of object '_Global' failed" error

C

Conan Kelly

Hello all,

I'm trying to run some code from an error handler and I keep getting this message:

http://home.att.net/~ctbarbarin/files/progress_error.jpg

This happens whether I call a sub procedure from with in the error handler or whether I put the code directly in the error handler.

I works just fine if I run the sub procedure all by itself, but I can't get it to work from the error handler.

How can I get this to run from within the error handler?


Here is the code:


(error handler call and sub procedure)

PasteReplaceNulls_Err:
DisplayProgress
Exit Sub

End Sub

Sub DisplayProgress()
Dim plngFirstRow As Long
Dim plngFirstCol As Long
Dim plngCurrRow As Long
Dim plngCurrCol As Long
Dim plngCurrCell As Long
Dim plngTotalCells As Long

plngTotalCells = Selection.Cells.Count
plngFirstRow = Selection.Cells(1).Row
plngFirstCol = Selection.Cells(1).Column
plngCurrRow = Selection.Find("NULL", ActiveCell, xlFormulas).Row
plngCurrCol = Selection.Find("NULL", ActiveCell, xlFormulas).Column

plngCurrCell = ((plngCurrRow - plngFirstRow) * Selection.Columns.Count) + (plngCurrCol - plngFirstCol) + 1
MsgBox "Progress: " & FormatPercent(plngCurrCell / plngTotalCells, 2, vbTrue)

End Sub




(or error handler code)

PasteReplaceNulls_Err:
plngTotalCells = Selection.Cells.Count
plngFirstRow = Selection.Cells(1).Row
plngFirstCol = Selection.Cells(1).Column
plngCurrRow = Selection.Find("NULL", ActiveCell, xlFormulas).Row
plngCurrCol = Selection.Find("NULL", ActiveCell, xlFormulas).Column

plngCurrCell = ((plngCurrRow - plngFirstRow) * Selection.Columns.Count) + (plngCurrCol - plngFirstCol) + 1
MsgBox "Progress: " & FormatPercent(plngCurrCell / plngTotalCells, 2, vbTrue)
Exit Sub

End Sub

(Variable names were declared at the top of the sub)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top