Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Checking usewr has input a valid address

Good afternoon all (again)
The object of the exercise is to check that the user has input a valid
address (as I'm FAIRLY sure it's not possible to check if a named range
exists in a workbook without opening it).

Sub ATestForValidRange()
On Error Resume Next
MyValue = InputBox("Enter a value:", "Test for valid range")
Set MyRange = Range(MyValue)
On Error GoTo 0
If Not MyRange Is Nothing Then
MsgBox ("Valid Range")
Else
MsgBox ("Invalid Range")
End If
End Sub

This code functions OK, providing you input a valid range such as a5,
$a$5:$p$26 etc, but if you put in something like "25", it falls over with the
message"Object required" on the "If not myrange is nothing" line, instead of
correctlty branching to display an error message.

Can anyone out there help, please?

Thanks in advance

Pete


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 336
Default Checking usewr has input a valid address

Try this instead:

If TypeName(myRange) < "Empty" Then


"Peter Rooney" wrote:

Good afternoon all (again)
The object of the exercise is to check that the user has input a valid
address (as I'm FAIRLY sure it's not possible to check if a named range
exists in a workbook without opening it).

Sub ATestForValidRange()
On Error Resume Next
MyValue = InputBox("Enter a value:", "Test for valid range")
Set MyRange = Range(MyValue)
On Error GoTo 0
If Not MyRange Is Nothing Then
MsgBox ("Valid Range")
Else
MsgBox ("Invalid Range")
End If
End Sub

This code functions OK, providing you input a valid range such as a5,
$a$5:$p$26 etc, but if you put in something like "25", it falls over with the
message"Object required" on the "If not myrange is nothing" line, instead of
correctlty branching to display an error message.

Can anyone out there help, please?

Thanks in advance

Pete


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Checking usewr has input a valid address

Martin,

Spot on. Have a green tick and my thanks! :-)

Pete





"Martin" wrote:

Try this instead:

If TypeName(myRange) < "Empty" Then


"Peter Rooney" wrote:

Good afternoon all (again)
The object of the exercise is to check that the user has input a valid
address (as I'm FAIRLY sure it's not possible to check if a named range
exists in a workbook without opening it).

Sub ATestForValidRange()
On Error Resume Next
MyValue = InputBox("Enter a value:", "Test for valid range")
Set MyRange = Range(MyValue)
On Error GoTo 0
If Not MyRange Is Nothing Then
MsgBox ("Valid Range")
Else
MsgBox ("Invalid Range")
End If
End Sub

This code functions OK, providing you input a valid range such as a5,
$a$5:$p$26 etc, but if you put in something like "25", it falls over with the
message"Object required" on the "If not myrange is nothing" line, instead of
correctlty branching to display an error message.

Can anyone out there help, please?

Thanks in advance

Pete


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Checking usewr has input a valid address

The better way to improve your code is to declare myrange as range, then it
will work as originally intended.

Sub ATestForValidRange()
Dim MyRange as Range
On Error Resume Next
MyValue = InputBox("Enter a value:", "Test for valid range")
Set MyRange = Range(MyValue)
On Error GoTo 0
If Not MyRange Is Nothing Then
MsgBox ("Valid Range")
Else
MsgBox ("Invalid Range")
End If
End Sub


--
Regards,
Tom Ogilvy



"Peter Rooney" wrote in message
...
Martin,

Spot on. Have a green tick and my thanks! :-)

Pete





"Martin" wrote:

Try this instead:

If TypeName(myRange) < "Empty" Then


"Peter Rooney" wrote:

Good afternoon all (again)
The object of the exercise is to check that the user has input a valid
address (as I'm FAIRLY sure it's not possible to check if a named

range
exists in a workbook without opening it).

Sub ATestForValidRange()
On Error Resume Next
MyValue = InputBox("Enter a value:", "Test for valid range")
Set MyRange = Range(MyValue)
On Error GoTo 0
If Not MyRange Is Nothing Then
MsgBox ("Valid Range")
Else
MsgBox ("Invalid Range")
End If
End Sub

This code functions OK, providing you input a valid range such as a5,
$a$5:$p$26 etc, but if you put in something like "25", it falls over

with the
message"Object required" on the "If not myrange is nothing" line,

instead of
correctlty branching to display an error message.

Can anyone out there help, please?

Thanks in advance

Pete




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default Checking usewr has input a valid address

Tom,

That's neat. Thank you, and a green tick for YOU, too! :-)

Regards

Pete



"Tom Ogilvy" wrote:

The better way to improve your code is to declare myrange as range, then it
will work as originally intended.

Sub ATestForValidRange()
Dim MyRange as Range
On Error Resume Next
MyValue = InputBox("Enter a value:", "Test for valid range")
Set MyRange = Range(MyValue)
On Error GoTo 0
If Not MyRange Is Nothing Then
MsgBox ("Valid Range")
Else
MsgBox ("Invalid Range")
End If
End Sub


--
Regards,
Tom Ogilvy



"Peter Rooney" wrote in message
...
Martin,

Spot on. Have a green tick and my thanks! :-)

Pete





"Martin" wrote:

Try this instead:

If TypeName(myRange) < "Empty" Then


"Peter Rooney" wrote:

Good afternoon all (again)
The object of the exercise is to check that the user has input a valid
address (as I'm FAIRLY sure it's not possible to check if a named

range
exists in a workbook without opening it).

Sub ATestForValidRange()
On Error Resume Next
MyValue = InputBox("Enter a value:", "Test for valid range")
Set MyRange = Range(MyValue)
On Error GoTo 0
If Not MyRange Is Nothing Then
MsgBox ("Valid Range")
Else
MsgBox ("Invalid Range")
End If
End Sub

This code functions OK, providing you input a valid range such as a5,
$a$5:$p$26 etc, but if you put in something like "25", it falls over

with the
message"Object required" on the "If not myrange is nothing" line,

instead of
correctlty branching to display an error message.

Can anyone out there help, please?

Thanks in advance

Pete





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
checking hyperlinks are valid Garbagh Excel Discussion (Misc queries) 2 September 21st 17 05:04 PM
The address of this site is not valid. Check the address and try kevin Excel Discussion (Misc queries) 1 February 11th 09 01:30 PM
checking hyperlinks are valid Rafael Guerreiro Osorio Excel Discussion (Misc queries) 0 November 30th 06 01:34 PM
Checking user has input a valid address. Peter Rooney Excel Programming 1 March 7th 06 10:57 PM
Checking If Hyperlink Is Valid Steve[_32_] Excel Programming 2 September 14th 03 03:05 AM


All times are GMT +1. The time now is 02:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"