Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Data Validation Formula

Geetings,

I'm trying to use data validation to only allow letters or numbers to be
entered in a cell (I don't want the user to enter any symbols). Can you help
me write a formula for that?

Any help would be GREATLY appreciated!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Data Validation Formula

Since you posted in the programming group, how about some code.
The code below goes in the module for the sheet in question.
Access that by right-clicking the sheet tab and selecting "View Code".
Copy and paste the code in there.
It works only on cell B5, change that to the cell desired.
See the line marked with <<<<.
Only spaces, numbers and upper and lower case letters are allowed.
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

'--------------------
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo OuttaHere
If Target.Address = "$B$5" Then '<<<< change cell
Application.EnableEvents = False
Dim strText As String
Dim lngN As Long
Const str_Chars As String = "[0-9a-zA-Z ]"
strText = Target.Text

For lngN = 1 To Len(strText)
If Not Mid$(strText, lngN, 1) Like str_Chars Then
MsgBox "Only numbers or alphabetic characters allowed. ", _
vbOKOnly, " Blame Dan"
Application.Undo
Exit For
End If
Next 'lngN
End If
OuttaHe
Application.EnableEvents = True
End Sub
'--------------



"Dan N"
wrote in message
Greetings,

I'm trying to use data validation to only allow letters or numbers to be
entered in a cell (I don't want the user to enter any symbols). Can you help
me write a formula for that?

Any help would be GREATLY appreciated!
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Data Validation Formula

Jim,

That's outstanding! The code worked perfectly! After working on this for so
long I can't begin to tell you how much I appreciate the help. I really loved
the "Blame Dan" part. It made me laugh. I'm keeping it!

Great job. Thanks. - Dan N

"Jim Cone" wrote:

Since you posted in the programming group, how about some code.
The code below goes in the module for the sheet in question.
Access that by right-clicking the sheet tab and selecting "View Code".
Copy and paste the code in there.
It works only on cell B5, change that to the cell desired.
See the line marked with <<<<.
Only spaces, numbers and upper and lower case letters are allowed.
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

'--------------------
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo OuttaHere
If Target.Address = "$B$5" Then '<<<< change cell
Application.EnableEvents = False
Dim strText As String
Dim lngN As Long
Const str_Chars As String = "[0-9a-zA-Z ]"
strText = Target.Text

For lngN = 1 To Len(strText)
If Not Mid$(strText, lngN, 1) Like str_Chars Then
MsgBox "Only numbers or alphabetic characters allowed. ", _
vbOKOnly, " Blame Dan"
Application.Undo
Exit For
End If
Next 'lngN
End If
OuttaHe
Application.EnableEvents = True
End Sub
'--------------



"Dan N"
wrote in message
Greetings,

I'm trying to use data validation to only allow letters or numbers to be
entered in a cell (I don't want the user to enter any symbols). Can you help
me write a formula for that?

Any help would be GREATLY appreciated!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Data Validation Formula

You are very welcome.
Jim Cone


"Dan N"
wrote in message...
Jim,
That's outstanding! The code worked perfectly! After working on this for so
long I can't begin to tell you how much I appreciate the help. I really loved
the "Blame Dan" part. It made me laugh. I'm keeping it!
Great job. Thanks. - Dan N



"Jim Cone" wrote:
Since you posted in the programming group, how about some code.
The code below goes in the module for the sheet in question.
Access that by right-clicking the sheet tab and selecting "View Code".
Copy and paste the code in there.
It works only on cell B5, change that to the cell desired.
See the line marked with <<<<.
Only spaces, numbers and upper and lower case letters are allowed.
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

'--------------------
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo OuttaHere
If Target.Address = "$B$5" Then '<<<< change cell
Application.EnableEvents = False
Dim strText As String
Dim lngN As Long
Const str_Chars As String = "[0-9a-zA-Z ]"
strText = Target.Text

For lngN = 1 To Len(strText)
If Not Mid$(strText, lngN, 1) Like str_Chars Then
MsgBox "Only numbers or alphabetic characters allowed. ", _
vbOKOnly, " Blame Dan"
Application.Undo
Exit For
End If
Next 'lngN
End If
OuttaHe
Application.EnableEvents = True
End Sub
'--------------



"Dan N"
wrote in message
Greetings,
I'm trying to use data validation to only allow letters or numbers to be
entered in a cell (I don't want the user to enter any symbols). Can you help
me write a formula for that?
Any help would be GREATLY appreciated!


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 469
Default Data Validation Formula

It looks that your code is headed in my direction. changeing range etc. Want
to require data input into all cells in the row. if blank donot allow move to
another cell
possible ? Have not found this thru excel data validation.
Thanks

"Jim Cone" wrote:

Since you posted in the programming group, how about some code.
The code below goes in the module for the sheet in question.
Access that by right-clicking the sheet tab and selecting "View Code".
Copy and paste the code in there.
It works only on cell B5, change that to the cell desired.
See the line marked with <<<<.
Only spaces, numbers and upper and lower case letters are allowed.
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

'--------------------
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo OuttaHere
If Target.Address = "$B$5" Then '<<<< change cell
Application.EnableEvents = False
Dim strText As String
Dim lngN As Long
Const str_Chars As String = "[0-9a-zA-Z ]"
strText = Target.Text

For lngN = 1 To Len(strText)
If Not Mid$(strText, lngN, 1) Like str_Chars Then
MsgBox "Only numbers or alphabetic characters allowed. ", _
vbOKOnly, " Blame Dan"
Application.Undo
Exit For
End If
Next 'lngN
End If
OuttaHe
Application.EnableEvents = True
End Sub
'--------------



"Dan N"
wrote in message
Greetings,

I'm trying to use data validation to only allow letters or numbers to be
entered in a cell (I don't want the user to enter any symbols). Can you help
me write a formula for that?

Any help would be GREATLY appreciated!



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
data validation formula Wanna Learn Excel Discussion (Misc queries) 1 May 13th 09 08:16 PM
Data validation formula Pasty Excel Worksheet Functions 1 November 24th 06 02:29 PM
data validation formula Kimberly Excel Discussion (Misc queries) 4 November 12th 06 03:01 PM
Help with Formula (data validation maybe?) [email protected] Excel Programming 5 March 22nd 06 07:05 PM
Data Validation with Formula Annabelle Excel Discussion (Misc queries) 2 June 28th 05 10:11 PM


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

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"