D
dan dungan
Hi James or anyone,
I'm attempting to understand error handling.
I copied this from James into a test worksheet and it produced runtime
error 1004, method range of object failed on Range(rgStr).Select
I used the procedure on a worksheet with data in range a1:h23.
Sub Sel()
Dim rgStr As String, c As Range
For Each c In Range("a1:h23")
If c <> "" Then
If rgStr = "" Then
rgStr = c.Address
Else
rgStr = rgStr & "," & c.Address
End If
End If
Next c
Range(rgStr).Select
End Sub
With my limited knowledge I think this means there is no more data to
process in my range so the procedure produced the error. I figure the
procedure needs error handling.
I added On Error GoTo error_handler1 after the dim statement and
error_handler1: after Range(rgStr).Select.
The procedure still produces the same error dialog.
It seems to me that even if my error handler worked, I would lose the
values held in rgStr.
It also seems that since this procedure is returning values it should
be a function.
Please help clarify my understanding.
Dan Dungan
I'm attempting to understand error handling.
I copied this from James into a test worksheet and it produced runtime
error 1004, method range of object failed on Range(rgStr).Select
I used the procedure on a worksheet with data in range a1:h23.
Sub Sel()
Dim rgStr As String, c As Range
For Each c In Range("a1:h23")
If c <> "" Then
If rgStr = "" Then
rgStr = c.Address
Else
rgStr = rgStr & "," & c.Address
End If
End If
Next c
Range(rgStr).Select
End Sub
With my limited knowledge I think this means there is no more data to
process in my range so the procedure produced the error. I figure the
procedure needs error handling.
I added On Error GoTo error_handler1 after the dim statement and
error_handler1: after Range(rgStr).Select.
The procedure still produces the same error dialog.
It seems to me that even if my error handler worked, I would lose the
values held in rgStr.
It also seems that since this procedure is returning values it should
be a function.
Please help clarify my understanding.
Dan Dungan