What I would do is move the entire code to a Function,
passing the textbox content.
Have the function perform the test, then return something significant. 
(like true/false or a value to replace the textbox content)
 
You still have to have a _Change event for each textbox,
but the code is much simpler and easier to maintain.

Paul
-----------------------------------------
“Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can.” - John Wesley
-----------------------------------------


>________________________________
> From: Mr_Bill <egge...@gmail.com>
>To: excel-macros@googlegroups.com 
>Sent: Wednesday, September 24, 2014 1:48 PM
>Subject: $$Excel-Macros$$ VBA Numbers only in Textbox
>  
>
>
>Can this code be adapted to work with only certain textboxs? I 
have 15 boxes in a form that require a number to be input and all are 
named wtBox1 - wtBox15
>
>
>Dim LastPosition As Long Private Sub TextBox1_Change() Static LastText As 
>String Static SecondTime As Boolean If Not SecondTime Then With TextBox1 ' 
>Digits Only (no plus or minus) 'If .Text Like "*[!0-9]*" Then ' Digits Only 
>(plus or minus allowed) 'If .Text Like "*[!0-9+-]*" Or .Text Like "?*[+-]*" 
>Then ' Floating Point Numbers (no plus or minus) 'If .Text Like "*[!0-9.]*" Or 
>.Text Like "*.*.*" Then ' Floating Point Numbers (plus or minus allowed) If 
>.Text Like "*[!0-9.+-]*" Or .Text Like "?*[+-]*" Or .Text Like "*.*.*" Then 
>Beep SecondTime = True .Text = LastText .SelStart = LastPosition Else LastText 
>= .Text End If End With End If SecondTime = False
End Sub Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As 
Integer, _ ByVal X As Single, ByVal Y As Single) With TextBox1 LastPosition = 
.SelStart 'Place any other MouseDown event code here End With
End Sub Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) 
With TextBox1 LastPosition = .SelStart 'Place any other KeyPress checking code 
here End With
End Sub
>
>Thank you 
-- 
>Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
>=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
>https://www.facebook.com/discussexcel
> 
>FORUM RULES
> 
>1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
>Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
>quick attention or may not be answered.
>2) Don't post a question in the thread of another member.
>3) Don't post questions regarding breaking or bypassing any security measure.
>4) Acknowledge the responses you receive, good or bad.
>5) Jobs posting is not allowed.
>6) Sharing copyrighted material and their links is not allowed.
> 
>NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
>members are not responsible for any loss.
>--- 
>You received this message because you are subscribed to the Google Groups "MS 
>EXCEL AND VBA MACROS" group.
>To unsubscribe from this group and stop receiving emails from it, send an 
>email to excel-macros+unsubscr...@googlegroups.com.
>To post to this group, send email to excel-macros@googlegroups.com.
>Visit this group at http://groups.google.com/group/excel-macros.
>For more options, visit https://groups.google.com/d/optout.
>
>
>    

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.

Reply via email to