Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Check cell value exactly

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Check cell value exactly

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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Check cell value exactly

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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Check cell value exactly

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 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
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
check or uncheck a check box based on a cell value RTKCPA Excel Discussion (Misc queries) 1 February 3rd 10 03:11 PM
Copy and move check box (check boxes) with new cell link? Marty Excel Worksheet Functions 1 January 20th 10 07:43 PM
Cannot check the check mark box in cell ac Excel Worksheet Functions 1 February 15th 08 10:24 PM
check to see if a cell is blank if not populate adjacent cell wit. Frusterated Excel Discussion (Misc queries) 6 September 14th 07 10:55 PM
Check if Conditional Format is True or False / Check cell Color Kevin McCartney Excel Worksheet Functions 5 June 29th 07 11:12 AM


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

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"