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: 1
Default Validating a unique reference in a textbox


Hello, I am trying to do a data validation where the reference numbe
entered on a textbox on a form (which adds a record to the activ
sheet) has to be unique and not already in the workbook. I alread
have a find facility which can search selected sheets within th
workbook and I am trying to adapt this so that it will search the sam
sheets and bring up a message box if the number already exists (ie
match). I can't get it to work (it is bringing up the message box o
any number I input) & would appreciate if someone could help me on it!
Here is the relevant part of my coding:

Dim Findstring As String
Dim Rng As Excel.Range
Dim mysheets As Excel.Sheets
Dim objsheet As Excel.Worksheet

Set mysheets = Worksheets(Array("Sheet 2", "Sheet 3", "Sheet 4", _
"Sheet 5", "Sheet 10", "Sheet 11"))

For Each objsheet In mysheets
Set Rng = objsheet.Columns("A").Find(What:=Findstring, _
After:=Range("A5"), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)
If Not Rng Is Nothing Then
MsgBox "The reference you have entered already exists o
the database.", vbExclamation, "Box reference already exists"
TextBox1.SetFocus
Exit Sub
End If

Next
'rest of my coding for other things

Thanks

--
Blondegir
-----------------------------------------------------------------------
Blondegirl's Profile: http://www.excelforum.com/member.php...fo&userid=2961
View this thread: http://www.excelforum.com/showthread.php?threadid=54284

 
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
Validating number of characters in textbox Blondegirl[_9_] Excel Programming 2 May 10th 06 01:57 PM
validating input of textbox before publishing eyesonly1965 Excel Programming 4 May 7th 06 03:18 PM
validating input in textbox Jean-Pierre D via OfficeKB.com Excel Programming 1 August 15th 05 08:37 PM
Excel VBA - Cursor disappears when validating content of a TextBox lonewolfbr Excel Programming 0 September 16th 04 09:49 PM
Validating Entry into Textbox Brad[_11_] Excel Programming 1 December 4th 03 02:58 PM


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