LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Data Validation - Accept Only Certain Numbers/Characters

The following code came from a previous question; purpose was to limit input
to only the numbers 1-9 and alpha characters. I need to modify it so that it
will accept a number anywhere from 0-100% and the letter 'M'. Have tried
various ways to change the 'Const str_Chars As String', such as
"[0.00-100.00%,m,M]" etc., to no avail. Can someone please advise the proper
way to designate the string?

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

 
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
Dependent Data Validation with Illegal Characters hjneedshelp Excel Discussion (Misc queries) 10 October 14th 16 10:07 PM
How do i get Data Validation to accept another workbook? Natalya Excel Discussion (Misc queries) 2 June 18th 08 08:19 PM
Data Validation - Only Allowing certain characters Marcus Excel Worksheet Functions 1 May 28th 07 01:34 PM
Problem with Data Validation and limiting characters MagnoliaSouth Excel Worksheet Functions 2 October 2nd 06 02:52 AM
Data validation, alpha or numeric characters tsammons Excel Programming 4 January 11th 06 02:03 AM


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