PDA

View Full Version : Preventing duplicate integers in PowerPoint vba textbox



brandy
02-07-2016, 07:20 PM
I have a vba textbox on a PowerPoint slide. Users will type a few integers in the range from 1 to 7 into the textbox, but I want the program to simply ignore attempts to enter duplicate integers. I suppose I need a little vba script for the textbox, no? Thank you.:yes

SamT
02-07-2016, 11:19 PM
Hey brandy, welome to the forum.

Do you mean that you don't want a String like 12234 to be used? That would require one solution

If you don't want the same integer to be used during a second usage, that would be a different solution.

John Wilson
02-08-2016, 12:46 AM
As Sam (and Steve in the other forum you posted to) are saying give as full an explanation of exactly what and why you need to do.

SamT
02-08-2016, 09:33 AM
Cross Posting (http://www.vbaexpress.com/forum/showthread.php?18537-Cross-Posting&p=137004&viewfull=1#post137004)

John Wilson
02-08-2016, 12:30 PM
You could try this:


Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
Case 49 To 55, 8, 27 'allow ESC and Backspace and 1-7
'check not there
If InStr(1, Me.TextBox1.Text, Chr(KeyCode)) > 0 Then KeyCode = 0
Case Else
KeyCode = 0
End Select
End Sub