Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Search for existing values in woorksheet!?

Hi all,

i need some help coming up with a code.

I have a Userform in wich users add new data to a database.
When a user enters a new post he/she needs to enter a number for
example 6501. I need a code that search the entire column ( A ) for
just this number, and if it already exist a MsgBox pops up and inform
the user!

Grateful for all help i can get!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Search for existing values in woorksheet!?


with Worksheets("Sheet1").Columns("A:A")
set oCell = .Find (Textbox1.Text)
If not oCell Is Nothing Then
Msgbox "Value already exists"
End If
End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Daniel" wrote in message
m...
Hi all,

i need some help coming up with a code.

I have a Userform in wich users add new data to a database.
When a user enters a new post he/she needs to enter a number for
example 6501. I need a code that search the entire column ( A ) for
just this number, and if it already exist a MsgBox pops up and inform
the user!

Grateful for all help i can get!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default Search for existing values in woorksheet!?

Daniel

You could use a function similar to below

Function CheckValues(lInputNo As Integer) As Boolean
Dim lLastRow As Long
lLastRow = Range("A65536").End(xlUp).Row
If Not Range("A1:A" & lLastRow).Find(lInputNo) Is Nothing Then
CheckValues = True
Exit Function
End If
CheckValues = False
End Function

The lInputNo parameter is the entry from your user form. This then finds
the last row currently in column A and uses the find method of the range
object to see if the number exists in this range. If it doesn't the method
returns NOTHING and CheckValue=False and you should show no msgbox. If it
finds a duplicate it returns true and you should show a message box. My
test sub may help to explain the inputting of the parameter too

Sub Test()
Dim x As Boolean
x = CheckValues(InputBox("Enter a number", "Test"))
If x = True Then
MsgBox "Duplicate number", vbOKCancel
End If
End Sub
--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"Daniel" wrote in message
m...
Hi all,

i need some help coming up with a code.

I have a Userform in wich users add new data to a database.
When a user enters a new post he/she needs to enter a number for
example 6501. I need a code that search the entire column ( A ) for
just this number, and if it already exist a MsgBox pops up and inform
the user!

Grateful for all help i can get!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Search for existing values in woorksheet!?

To check for the existence of the number in column A you
can use the WorksheetFunction CountIf. I will call the
stored value of the number entered in your
UserForm 'InputNumber' and define a boolean variable
NewNumber

NewNumber = False

While Not(NewNumber)
' Put your code here to display your userform and store
the entered value in InputNumber
NewNumber = (WorksheetFunction.CountIf(Range
("A:A"),InputNumber)=0)
If Not(NewNumber) Then MsgBox "Number Already Exists!"
Wend

This loops through the input routine until you have a
number that does not already exist in column A (displaying
the messagebox if it finds the number already in column A)

Might need some tweaks to fit your code (and to deal with
null entries, error trapping, etc.), but the general idea
hopefully can do what you need to do.

K Dales

-----Original Message-----
Hi all,

i need some help coming up with a code.

I have a Userform in wich users add new data to a

database.
When a user enters a new post he/she needs to enter a

number for
example 6501. I need a code that search the entire column

( A ) for
just this number, and if it already exist a MsgBox pops

up and inform
the user!

Grateful for all help i can get!
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Search for existing values in woorksheet!?

Thanx for all help, i tested them all and found them very helpful!


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
Formula text in woorksheet cell mexmex Excel Discussion (Misc queries) 2 October 10th 09 02:43 PM
Copy and Paste information from woorksheet onto different workbook T-bone Excel Discussion (Misc queries) 3 June 27th 07 04:12 PM
Woorksheet locked on active cell ESD Excel Worksheet Functions 1 March 18th 05 02:22 PM
How do I delete Rows from my woorksheet? Leslie Excel Worksheet Functions 8 December 15th 04 05:33 PM
Search/Filter to find values in another range based on two cell values Andy Excel Programming 2 April 29th 04 04:08 PM


All times are GMT +1. The time now is 04:08 AM.

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"