ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Mutually exclusive values (https://www.excelbanter.com/excel-programming/357674-mutually-exclusive-values.html)

scantor145[_23_]

Mutually exclusive values
 

Excel 2003
Visual Basic 6.3

I have a form with 24 text boxes. The names of the text boxes all
start with “txt”, e.g. txtCHOL, txtALB, etc. The values that are
entered into the text boxes can range from 1 to 24. Is there an easy
way (VB code) to check that each box has a different number, that is,
mutually exclusive.

Thanks


--
scantor145
------------------------------------------------------------------------
scantor145's Profile: http://www.excelforum.com/member.php...o&userid=14766
View this thread: http://www.excelforum.com/showthread...hreadid=528559


Bob Phillips[_6_]

Mutually exclusive values
 
Dim tb As Control
Dim collNums As Collection
Dim cTBs As Long

Set collNums = New Collection
For Each tb In Me.Controls
If TypeName(tb) = "TextBox" Then
cTBs = cTBs + 1
On Error Resume Next
collNums.Add tb.Text, tb.Text
On Error GoTo 0
End If
Next tb
If collNums.Count < cTBs Then
MsgBox "All values must be unique"
End If


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"scantor145" wrote
in message ...

Excel 2003
Visual Basic 6.3

I have a form with 24 text boxes. The names of the text boxes all
start with "txt", e.g. txtCHOL, txtALB, etc. The values that are
entered into the text boxes can range from 1 to 24. Is there an easy
way (VB code) to check that each box has a different number, that is,
mutually exclusive.

Thanks


--
scantor145
------------------------------------------------------------------------
scantor145's Profile:

http://www.excelforum.com/member.php...o&userid=14766
View this thread: http://www.excelforum.com/showthread...hreadid=528559





All times are GMT +1. The time now is 03:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com