PC Review


Reply
Thread Tools Rate Thread

How do I test whether a string is a valid cell reference?

 
 
JT
Guest
Posts: n/a
 
      15th Apr 2010
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
 
Reply With Quote
 
 
 
 
sali
Guest
Posts: n/a
 
      15th Apr 2010
"JT" <(E-Mail Removed)> je napisao u poruci interesnoj
grupi:e3c91e3f-9994-413e-9e8b-(E-Mail Removed)...
>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.


when testing expressions, i let excel to do the job, and report, if error,
so

function test1(reference as string) as boolean
dim v as range
on error resume next
set v=range(reference) 'try to use referenced range, is address valid?
if err.number>0 then
exit functio 'return false
end if
test1=true
end function


 
Reply With Quote
 
JLatham
Guest
Posts: n/a
 
      15th Apr 2010
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
> .
>

 
Reply With Quote
 
JT
Guest
Posts: n/a
 
      15th Apr 2010
On Apr 15, 1:29*pm, JLatham <JLat...@discussions.microsoft.com> 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))),"INVALID CELL
REFERENCE","OK"))

John
 
Reply With Quote
 
JLatham
Guest
Posts: n/a
 
      16th Apr 2010
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 <JLat...@discussions.microsoft.com> 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))),"INVALID CELL
> REFERENCE","OK"))
>
> John
> .
>

 
Reply With Quote
 
JT
Guest
Posts: n/a
 
      16th Apr 2010
On Apr 16, 1:43*am, JLatham <JLat...@discussions.microsoft.com> wrote:
> Glad our ideas gave you an idea. *Didn't realize you wanted to do it ina
> worksheet cell, so I *gave up the VBA code.
>
>
>
> "JT" wrote:
> > On Apr 15, 1:29 pm, JLatham <JLat...@discussions.microsoft.com> 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))),"INVALID CELL
> > REFERENCE","OK"))

>
> > John
> > .- Hide quoted text -

>
> - Show quoted text -


I was looking to do both, so thanks!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
I need a test to see that a string is a valid path to a file AAaron123 Microsoft C# .NET 7 26th Feb 2009 01:09 AM
substitute the filename in a cell reference with a string in another cell. flummi Microsoft Excel Misc 11 22nd Feb 2006 01:14 PM
Input cell reference is not valid (One Variable Data Table) =?Utf-8?B?RG90dG9yZQ==?= Microsoft Excel Worksheet Functions 9 1st Sep 2005 03:05 PM
To to check whether a string is a valid reference =?Utf-8?B?TmljayBTaGlua2lucw==?= Microsoft Excel Programming 3 17th Dec 2004 04:27 PM
Convert text string in format of cell reference to a cell reference =?Utf-8?B?RnJhbms=?= Microsoft Excel Misc 1 16th Dec 2003 08:52 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:29 PM.