Below is a simple sub to get user selected range - this is an example from John Walkenbach's book.
What I can't understand here is that why in this program, "On error resume next" and "On error goto 0" have to be placed exactly where they are. I tried to place these two statements in different places within the procedure, then I got errors. Please explain your thoughts - think about those early days when you just started to learn VBA did this kind of question bother you as well?
Apologies if this question sounds stupid to you. And, thanks!
Dim UserRange As Range
Prompt = "Select a range for the random numbers."
Title = "Select a range"
' Display the Input Box
On Error Resume Next
Set UserRange = Application.InputBox( _
Type:=8) 'Range selection
On Error GoTo 0
' Was the Input Box canceled?
If UserRange Is Nothing Then
UserRange.Formula = "=RAND()"