ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   "Method 'Selection' of object '_Global' failed" error (https://www.excelbanter.com/excel-programming/369418-method-selection-object-_global-failed-error.html)

Conan Kelly

"Method 'Selection' of object '_Global' failed" error
 
Hello all,

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

http://home.att.net/~ctbarbarin/file...ress_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)



--
Thanks for any help anyone can provide,

Conan Kelly




All times are GMT +1. The time now is 03:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com