Set myRng = Nothing
On Error Resume Next
Set myRng = Application.InputBox(prompt:="Select your range to sort", _
Default:=Selection.Areas(1).Address, Type:=8).Areas(1)
On Error GoTo 0
myRng is an object variable (a range object to be specific)
set myrng = nothing
tells is the equivalent of setting a number to 0. I want to make sure that my
variable is initialized to 0.
application.inputbox(prompt:="...", type:=8)
expects the user to select a range (type:=8 is the portion that does that).
If the user hits cancel, then that line will cause an error.
To avoid that possible error, I tell excel to ignore any errors that can happen
with "on error resume next". But as soon as I'm done trying to get that range,
I'll turn error checking back to excel ("on error goto 0"). It doesn't really
mean to goto 0 (like a line number). It's the syntax to tell excel that it
should handle any future errors.
After trying to get the range from the user, I check to see what myRng is. If
the user hit cancel, then that variable didn't change (from Nothing). So I just
check with this line: "If myRng is nothing then".
Oh sorry.I found my mistake.now it is working.I have one more request.Can you
please explain briefly your first code line by line,some lines like goto 0,
=Nothing or Resume next is not clear to me.
thanx for your time Dave