Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Validate Textbox entry

Hi all,

Hope everyone that reads this is fine and the person who solves my problem
lives to at least 93 years of age.

Problem: I have a Textbox within a Userform with which I want the user to
input a valid spreadsheet cell address.

At the moment, the code that I have written to check the value within the
Textbox looks to see if the first character is not numeric and the last
character is numeric. The massive hole in this test is that someone could
input 'DAVID3' and it would pass.

Is there a way to check for a valid spreadsheet cell address?

Regards,


David Seebaran.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Validate Textbox entry

You could use something like:

Option Explicit
Sub testme()

Dim testRng As Range
Dim myStr As String

myStr = "a1"
'myStr = "Not a Range!"

Set testRng = Nothing
On Error Resume Next
Set testRng = ActiveSheet.Range(myStr)
On Error GoTo 0

If testRng Is Nothing Then
MsgBox "Nope"
Else
MsgBox "Yep"
End If

End Sub




David Seebaran wrote:

Hi all,

Hope everyone that reads this is fine and the person who solves my problem
lives to at least 93 years of age.

Problem: I have a Textbox within a Userform with which I want the user to
input a valid spreadsheet cell address.

At the moment, the code that I have written to check the value within the
Textbox looks to see if the first character is not numeric and the last
character is numeric. The massive hole in this test is that someone could
input 'DAVID3' and it would pass.

Is there a way to check for a valid spreadsheet cell address?

Regards,

David Seebaran.


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Validate Textbox entry

Dim rng as Range
On Error Resume Next
set rng = Range(Textbox1.Text)
On Error goto 0
if rng is nothing then
msgbox "Invalid Range"
End if

--
Regards,
Tom Ogilvy



"David Seebaran" wrote in message
...
Hi all,

Hope everyone that reads this is fine and the person who solves my problem
lives to at least 93 years of age.

Problem: I have a Textbox within a Userform with which I want the user to
input a valid spreadsheet cell address.

At the moment, the code that I have written to check the value within the
Textbox looks to see if the first character is not numeric and the last
character is numeric. The massive hole in this test is that someone could
input 'DAVID3' and it would pass.

Is there a way to check for a valid spreadsheet cell address?

Regards,


David Seebaran.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Validate Textbox entry

Hi David

Private Sub CommandButton1_Click()
Dim R As Range
On Error Resume Next
Set R = Range(TextBox1.Text)
If R Is Nothing Then
MsgBox TextBox1.Text & " is not an address"
Else
MsgBox R.Count & " cells are entered"
End If
End Sub

Note: This will accept "A:A" , "A1:D14" and any named range, therefore the
R.Count test. Simply use R(1) to get to the first cell of those instances.

Did you btw try the RefEdit control that allow you to pick a range also with
the mouse ?

HTH. Best wishes Harald (43 -and no cigarettes the last 8 days<:-)

"David Seebaran" skrev i melding
...
Hi all,

Hope everyone that reads this is fine and the person who solves my problem
lives to at least 93 years of age.

Problem: I have a Textbox within a Userform with which I want the user to
input a valid spreadsheet cell address.

At the moment, the code that I have written to check the value within the
Textbox looks to see if the first character is not numeric and the last
character is numeric. The massive hole in this test is that someone could
input 'DAVID3' and it would pass.

Is there a way to check for a valid spreadsheet cell address?

Regards,


David Seebaran.




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
Validate entry based on another cell value Dearoledad Excel Discussion (Misc queries) 3 May 15th 09 10:47 PM
Validate date entry in a text box. GoBow777 Excel Discussion (Misc queries) 0 July 30th 08 08:46 PM
validate duplicate entry in a column wangan Excel Discussion (Misc queries) 4 June 5th 07 01:38 PM
Validate Email address entry Rayasiom Excel Discussion (Misc queries) 2 May 31st 07 10:36 AM
Validate in WS to prevent dual data entry Jonah Excel Worksheet Functions 1 March 10th 06 05:22 AM


All times are GMT +1. The time now is 03:21 AM.

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

About Us

"It's about Microsoft Excel"