Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Validate entry based on another cell value | Excel Discussion (Misc queries) | |||
Validate date entry in a text box. | Excel Discussion (Misc queries) | |||
validate duplicate entry in a column | Excel Discussion (Misc queries) | |||
Validate Email address entry | Excel Discussion (Misc queries) | |||
Validate in WS to prevent dual data entry | Excel Worksheet Functions |