Laurawillow
New Member
- Joined
- Oct 28, 2015
- Messages
- 3
Hi
I am trying to write some code which will check text entered in each of 5 textboxes on a form, against a column of data already entered, starting cell B2.
I'm a bit of a newbie so please excuse if my terminology isn't very good! I can get the result I want checking one textbox against one cell, but don't know how to code to say check all textboxes against all entries in the column without my Excel just getting stuck in a loop.
I've been working on variations of:
Dim x
Dim dup As Boolean
x = 2
If TextBox2.Value = Cells(x, 2) Then
dup = True
x = x + 1
Do Until x = 1000
Loop
End If
If dup = True Then
MsgBox "Duplicate found. Please check and re-enter"
Else
MsgBox "No duplicates found."
End If
However, this overwrites dup each time so will only work if the duplicate is in the last cell it checks, so need to add a End Sub. And then make it neater, quicker, and go through and check textbox 3-6 in the same way.
Or there is a totally better and more sensible way of doing this with some sort of match function, though I haven't been able to find one.
Any help really appreciated, before I throw my computer out of the window!
Many thanks
Laura
I am trying to write some code which will check text entered in each of 5 textboxes on a form, against a column of data already entered, starting cell B2.
I'm a bit of a newbie so please excuse if my terminology isn't very good! I can get the result I want checking one textbox against one cell, but don't know how to code to say check all textboxes against all entries in the column without my Excel just getting stuck in a loop.
I've been working on variations of:
Dim x
Dim dup As Boolean
x = 2
If TextBox2.Value = Cells(x, 2) Then
dup = True
x = x + 1
Do Until x = 1000
Loop
End If
If dup = True Then
MsgBox "Duplicate found. Please check and re-enter"
Else
MsgBox "No duplicates found."
End If
However, this overwrites dup each time so will only work if the duplicate is in the last cell it checks, so need to add a End Sub. And then make it neater, quicker, and go through and check textbox 3-6 in the same way.
Or there is a totally better and more sensible way of doing this with some sort of match function, though I haven't been able to find one.
Any help really appreciated, before I throw my computer out of the window!
Many thanks
Laura