PC Review


Reply
Thread Tools Rate Thread

Check cell value exactly

 
 
learner
Guest
Posts: n/a
 
      24th Oct 2009
I'm trying to prevent typos entered through Userform:

id = TextBox1.Value
Worksheets("Eq'tDetails").Activate
Set rngToCheck = Columns("A:A")
Set rngValidate = rngToCheck.Find(id, LookIn:=xlValues,
SearchDirection:=xlPrevious)
If rngValidate Is Nothing Then
Unload Me
Worksheets("EntrySheet").Activate
MsgBox ("ID " & id & " Not Found")
GoTo LastLine 'Exits the code
End If
Else
' Rest of the code

I thought I got it but if, for example I accidentally enter "328" or "28" or
"8". etc. in TextBox1 instead of the true number"1328" I'm trying to
validate, Excell still accepts it and proceeds with the rest of the code. It
works fine otherwise.

Thank you for help.
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      24th Oct 2009
If you are looking for a whole cell match...

Set rngValidate = rngToCheck.Find(id, LookIn:=xlValues,
LookAt:=xlWhole,SearchDirection:=xlPrevious)

If this post helps click Yes
---------------
Jacob Skaria


"learner" wrote:

> I'm trying to prevent typos entered through Userform:
>
> id = TextBox1.Value
> Worksheets("Eq'tDetails").Activate
> Set rngToCheck = Columns("A:A")
> Set rngValidate = rngToCheck.Find(id, LookIn:=xlValues,
> SearchDirection:=xlPrevious)
> If rngValidate Is Nothing Then
> Unload Me
> Worksheets("EntrySheet").Activate
> MsgBox ("ID " & id & " Not Found")
> GoTo LastLine 'Exits the code
> End If
> Else
> ' Rest of the code
>
> I thought I got it but if, for example I accidentally enter "328" or "28" or
> "8". etc. in TextBox1 instead of the true number"1328" I'm trying to
> validate, Excell still accepts it and proceeds with the rest of the code. It
> works fine otherwise.
>
> Thank you for help.

 
Reply With Quote
 
learner
Guest
Posts: n/a
 
      24th Oct 2009
Thank you Jacob... so simple, but nevertheless very helpful for an amateur
like me. Very appreciated.

"Jacob Skaria" wrote:

> If you are looking for a whole cell match...
>
> Set rngValidate = rngToCheck.Find(id, LookIn:=xlValues,
> LookAt:=xlWhole,SearchDirection:=xlPrevious)
>
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "learner" wrote:
>
> > I'm trying to prevent typos entered through Userform:
> >
> > id = TextBox1.Value
> > Worksheets("Eq'tDetails").Activate
> > Set rngToCheck = Columns("A:A")
> > Set rngValidate = rngToCheck.Find(id, LookIn:=xlValues,
> > SearchDirection:=xlPrevious)
> > If rngValidate Is Nothing Then
> > Unload Me
> > Worksheets("EntrySheet").Activate
> > MsgBox ("ID " & id & " Not Found")
> > GoTo LastLine 'Exits the code
> > End If
> > Else
> > ' Rest of the code
> >
> > I thought I got it but if, for example I accidentally enter "328" or "28" or
> > "8". etc. in TextBox1 instead of the true number"1328" I'm trying to
> > validate, Excell still accepts it and proceeds with the rest of the code. It
> > works fine otherwise.
> >
> > Thank you for help.

 
Reply With Quote
 
Per Jessen
Guest
Posts: n/a
 
      24th Oct 2009
Hi

I am not quite sure what you want, but if user should always enter a
four digit number, then try comething like this:

id = TextBox1.Value
If Len(Textbox1.Value)<>4 Or Not IsNumeric(TextBox1.value) then
'Invalud entry
Exit sub
End If
Worksheets("Eq'tDetails").Activate
' Rest of code


Regards,
Per

On 24 Okt., 04:18, learner <lear...@discussions.microsoft.com> wrote:
> I'm trying to prevent typos entered through Userform:
>
> id = TextBox1.Value
> Worksheets("Eq'tDetails").Activate
> Set rngToCheck = Columns("A:A")
> Set rngValidate = rngToCheck.Find(id, LookIn:=xlValues,
> SearchDirection:=xlPrevious)
> * * * *If rngValidate Is Nothing Then
> * * * * * Unload Me
> * * * * * Worksheets("EntrySheet").Activate
> * * * * * MsgBox ("ID " & id & " Not Found")
> * * * * * GoTo LastLine 'Exits the code * * *
> * * * * * End If
> * * * * Else
> ' Rest of the code
>
> I thought I got it but if, for example I accidentally enter "328" or "28"or
> "8". etc. in TextBox1 instead of the true number"1328" I'm trying to
> validate, Excell still accepts it and proceeds with the rest of the code.It
> works fine otherwise.
>
> Thank you for help.


 
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
check or uncheck a check box based on a cell value RTKCPA Microsoft Excel Misc 1 3rd Feb 2010 03:11 PM
Copy and move check box (check boxes) with new cell link? Marty Microsoft Excel Worksheet Functions 1 20th Jan 2010 07:43 PM
Check if Conditional Format is True or False / Check cell Color =?Utf-8?B?S2V2aW4gTWNDYXJ0bmV5?= Microsoft Excel Worksheet Functions 5 29th Jun 2007 11:12 AM
Worksheet shakes like Rock n' Roll - how check the cell beside upon a singel cell change? Microsoft Excel Misc 1 4th May 2004 07:57 AM
command for using a check mark in a cell, not a check box =?Utf-8?B?aGFycmVsc29u?= Microsoft Access 1 16th Jan 2004 11:53 AM


Features
 

Advertising
 

Newsgroups
 


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