Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default How do I test whether a string is a valid cell reference?

Glad our ideas gave you an idea. Didn't realize you wanted to do it in a
worksheet cell, so I gave up the VBA code.

"JT" wrote:

On Apr 15, 1:29 pm, JLatham wrote:
Rather than trying to parse the text, you could use something like this:

'near the beginning of your process
Dim testForRange As Range
dim testAddress As String

...in here you get the string and
...put it in the example testAddress variable
... now you test it using error trapping
... assumes the range is to be on the current active sheet
On Error Resume Next
Set testForRange = ActiveSheet.Range(testAddress)
If Err < 0 then
'had an error, presumed invalid address string
MsgBox testAddress & " is not a valid range address."
Err.Clear ' clear the error
End If
On Error GoTo 0 ' reset error trapping



"JT" wrote:
I would like to develop a way of testing whether a string entered by a
user can be used by excel to define a range of cells within a sheet.


For example: "A1:C6" or "A:Z" would be OK but "iljfneklj" would not.


I'd like to have ways of doing this both in VBA and also using an
excel formula.


Are there any ideas out there?


Thanks


John
.- Hide quoted text -


- Show quoted text -


Thanks both

I have now also applied this principle to achieve the same using an
excel formula:

Where C36 contains a user input cell reference:
=IF(C36="","OK",IF(ISERROR(ROWS(INDIRECT(C36))),"I NVALID CELL
REFERENCE","OK"))

John
.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default How do I test whether a string is a valid cell reference?

On Apr 16, 1:43*am, JLatham wrote:
Glad our ideas gave you an idea. *Didn't realize you wanted to do it in a
worksheet cell, so I *gave up the VBA code.



"JT" wrote:
On Apr 15, 1:29 pm, JLatham wrote:
Rather than trying to parse the text, you could use something like this:


'near the beginning of your process
Dim testForRange As Range
dim testAddress As String


...in here you get the string and
...put it in the example testAddress variable
... now you test it using error trapping
... assumes the range is to be on the current active sheet
On Error Resume Next
Set testForRange = ActiveSheet.Range(testAddress)
If Err < 0 then
* *'had an error, presumed invalid address string
* *MsgBox testAddress & " is not a valid range address."
* *Err.Clear ' clear the error
End If
On Error GoTo 0 ' reset error trapping


"JT" wrote:
I would like to develop a way of testing whether a string entered by a
user can be used by excel to define a range of cells within a sheet..


For example: "A1:C6" or "A:Z" would be OK but "iljfneklj" would not..


I'd like to have ways of doing this both in VBA and also using an
excel formula.


Are there any ideas out there?


Thanks


John
.- Hide quoted text -


- Show quoted text -


Thanks both


I have now also applied this principle to achieve the same using an
excel formula:


Where C36 contains a user input cell reference:
=IF(C36="","OK",IF(ISERROR(ROWS(INDIRECT(C36))),"I NVALID CELL
REFERENCE","OK"))


John
.- Hide quoted text -


- Show quoted text -


I was looking to do both, so thanks!
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
How to test for valid 'Paste:=xlValues' before attempt. Bassman62 Excel Programming 2 December 11th 08 10:31 PM
How to test if a workbook variable is valid Jean-Pierre Bidon Excel Programming 3 December 7th 05 04:37 PM
Input cell reference is not valid (One Variable Data Table) Dottore Excel Worksheet Functions 9 September 1st 05 03:05 PM
How to test if a repertory is valid Alex St-Pierre Excel Programming 2 February 17th 05 02:30 AM
To to check whether a string is a valid reference Nick Shinkins Excel Programming 3 December 17th 04 04:27 PM


All times are GMT +1. The time now is 06:40 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"