Comparing values in textboxes evertime combo_changeevent trigers

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi, I have a long way of coding it however i want efficient code to comparing values in textboxes everytime combo value is changed.
I want to check in Userform textbox1 to textbox7 to see if there is any duplication....text values.


Thanks in advance.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi Pedie,
Not knowing all your details, does something like this example help?
Code:
Private Sub TextBox1_Change()
Dim ThisControl As Control
For Each ThisControl In Me.Controls
  If TypeName(ThisControl) = "TextBox" And ThisControl.Name <> "TextBox1" Then
    If ThisControl.Value = Me.TextBox1.Value Then _
      MsgBox "Got a duplicate entry here Pedie..."
  End If
Next ThisControl
End Sub
Perhaps you can reverse engineer this to get what you need. If not then can I have more details?

Dan

EDIT: (Oh yeah, remember this is in xl03...)
 
Upvote 0
Hi Dan, nice to see you around after a long time...
hmmm... it works great!:) however this check just texbox1 value right?

I want to check texbox1 with all other textboxes
like texbox2 with others, texbox3 with others and so one

Thanks again Dan!
 
Upvote 0
Yep, it only compares the textbox getting the entry to all the other textboxes.

You can however, (since you're only dealing with a handfull of textboxes), just add the same code to each textbox.
You'll want to amend each one like so:
Code:
Private Sub TextBox[B][COLOR=Red]2[/COLOR][/B]_Change()
Dim ThisControl As Control
For Each ThisControl In Me.Controls
  If TypeName(ThisControl) = "TextBox" And ThisControl.Name <> "TextBox[COLOR=Red][B]2[/B][/COLOR]" Then
    If ThisControl.Value = Me.TextBox[COLOR=Red][B]2[/B][/COLOR].Value Then _
      MsgBox "Got a duplicate entry here Pedie, in " & ThisControl.Name
  End If
Next ThisControl
End Sub
(I also added a bit to tell you in which textbox the duplicate(s) can be found...
 
Upvote 0
Yep! this will do...Thank you very much!
Earlier my code was full of Ifs:)

Thanks again Dan!
 
Upvote 0

Forum statistics

Threads
1,224,534
Messages
6,179,390
Members
452,909
Latest member
VickiS

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top