PC Review


Reply
Thread Tools Rate Thread

Code to Accept only a 0 or this...

 
 
6afraidbecause789@gmail.com
Guest
Posts: n/a
 
      22nd Oct 2008
Hi - The code below validates cells to accept any 3-digit combination
of 4 numbers, 1-4 (cells are text), and corrects users if they mistype
in the cell. How can the code also simply accept one digit, a 0--the
cells must contain a 0 or this 3-digit combo. Thanks to Rick and
others for the following code.

=============================

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myCell As Range
Dim myIntersect As Range
Set myIntersect = Intersect(Target, Me.Range("ABCper7"))
If myIntersect Is Nothing Then Exit Sub
On Error Resume Next 'just fly by errors
Application.EnableEvents = False
'code help by Rick R.
For Each myCell In myIntersect.Cells
myCell = Left(myCell, 3)
If myCell Like "[0-4][0-4][0-4]" And Not myCell Like "*0*0*" Then
myCell.Value = String(3, CStr(myCell.Value))
Else
MsgBox "First, enter a 0, 1, 2, 3, or 4 for an A score." & Chr(13) &
Chr(10) & _
"Then, enter a B score." & Chr(13) & Chr(10) & _
"Lastly, enter a C score." & Chr(13) & Chr(10) & _
"The value may be a 0 (unexcused absense) or any combination of" &
Chr(13) & Chr(10) & _
"1 through 4, with zeros allowed for B-C scores.", vbOKOnly

myCell.Value = ""
End If
Next myCell
Application.EnableEvents = True
On Error GoTo 0
End Sub

Thanks
 
Reply With Quote
 
 
 
 
Bernard Liengme
Guest
Posts: n/a
 
      22nd Oct 2008
This seems to work but I did not test the rest of your code

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myCell As Range
Dim myIntersect As Range
Set myIntersect = Intersect(Target, Me.Range("ABCper7"))
If myIntersect Is Nothing Then Exit Sub
On Error Resume Next 'just fly by errors
Application.EnableEvents = False
'code help by Rick R.
For Each myCell In myIntersect.Cells
If myCell.Value = 0 Then Exit For 'this is a new line
ETC....

best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

<(E-Mail Removed)> wrote in message
news:e75dee7e-775f-472d-bda5-(E-Mail Removed)...
> Hi - The code below validates cells to accept any 3-digit combination
> of 4 numbers, 1-4 (cells are text), and corrects users if they mistype
> in the cell. How can the code also simply accept one digit, a 0--the
> cells must contain a 0 or this 3-digit combo. Thanks to Rick and
> others for the following code.
>
> =============================
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim myCell As Range
> Dim myIntersect As Range
> Set myIntersect = Intersect(Target, Me.Range("ABCper7"))
> If myIntersect Is Nothing Then Exit Sub
> On Error Resume Next 'just fly by errors
> Application.EnableEvents = False
> 'code help by Rick R.
> For Each myCell In myIntersect.Cells
> myCell = Left(myCell, 3)
> If myCell Like "[0-4][0-4][0-4]" And Not myCell Like "*0*0*" Then
> myCell.Value = String(3, CStr(myCell.Value))
> Else
> MsgBox "First, enter a 0, 1, 2, 3, or 4 for an A score." & Chr(13) &
> Chr(10) & _
> "Then, enter a B score." & Chr(13) & Chr(10) & _
> "Lastly, enter a C score." & Chr(13) & Chr(10) & _
> "The value may be a 0 (unexcused absense) or any combination of" &
> Chr(13) & Chr(10) & _
> "1 through 4, with zeros allowed for B-C scores.", vbOKOnly
>
> myCell.Value = ""
> End If
> Next myCell
> Application.EnableEvents = True
> On Error GoTo 0
> End Sub
>
> Thanks



 
Reply With Quote
 
6afraidbecause789@gmail.com
Guest
Posts: n/a
 
      22nd Oct 2008
Hmmm, just one line of code. Thanks Bernard.
 
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
XP Pro Repair - will not accept key code Jim Smith Windows XP General 5 25th Jan 2010 04:45 PM
Pc accept my product code fow Works Suite 2005 =?Utf-8?B?bWxob25leQ==?= Microsoft Access Getting Started 9 23rd Dec 2008 01:11 PM
Auto Accept Meeting Request through code Richard R. Microsoft Outlook Calendar 0 16th Jun 2006 01:29 PM
caint get front page to accept key code =?Utf-8?B?YmVla3By?= Microsoft Frontpage 3 20th Mar 2005 04:15 AM
code to accept null values in recordset =?Utf-8?B?Z2VvbWlrZQ==?= Microsoft Access Form Coding 3 7th Feb 2005 04:58 PM


Features
 

Advertising
 

Newsgroups
 


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