![]() |
In textbox required only number without decimal
Hi, Please see the below coding, This working fine, But is accepting the decimal value also(.), What i required is when ever i type dot(.) it need to show msg "Please Enter Correct Number" Eg:1) 6161.8976, 2)98450.0, 3)8.874 need to show msg "Please Enter Correct Number" and delete the what ever typed that means nullstring in that textbox. Private Sub TextBox11_Change() Worksheets("FOR").Activate Range("C1").Select Range("C1").Value = TextBox11.Value If Not IsNumeric(TextBox11.Value) And TextBox11.Value < vbNullString Then MsgBox "Please Enter Correct Number" TextBox11.Value = vbNullString End If End Sub I'm very newbie for this coding. please anyone can help me on this. Thanks in advance Deen |
In textbox required only number without decimal
from If Not IsNumeric(TextBox11.Value) And TextBox11.Value < vbNullString Then to If Not IsNumeric(TextBox11.Value) And _ TextBox11.Value < vbNullString And _ instr(TextBox11.Value,".") 0 Then "Deen" wrote: Hi, Please see the below coding, This working fine, But is accepting the decimal value also(.), What i required is when ever i type dot(.) it need to show msg "Please Enter Correct Number" Eg:1) 6161.8976, 2)98450.0, 3)8.874 need to show msg "Please Enter Correct Number" and delete the what ever typed that means nullstring in that textbox. Private Sub TextBox11_Change() Worksheets("FOR").Activate Range("C1").Select Range("C1").Value = TextBox11.Value If Not IsNumeric(TextBox11.Value) And TextBox11.Value < vbNullString Then MsgBox "Please Enter Correct Number" TextBox11.Value = vbNullString End If End Sub I'm very newbie for this coding. please anyone can help me on this. Thanks in advance Deen |
In textbox required only number without decimal
What i required is when ever i type dot(.) it need to show msg "Please Enter Correct Number" That's a really intrusive way to go about it, and it deletes numbers-in-progress which may irk people who use the macro. How about just deleting any decimal values entered, e.g.: Private Sub TextBox11_Change() With Me.TextBox11 .Text = Replace(.Text, ".", "") End With End Sub Or another way with a little more flexibility. Specify the characters allowed to be entered, e.g. numbers but no decimal. Private Sub TextBox11_Change() Dim AllowChars As String Dim char As String, pos As Integer, newstr As String ' Select the allowable characters to be entered AllowChars = "0123456789" With Me.TextBox11 ' Loop through the characters in the textbox For pos = 1 To Len(.Text) char = Mid(.Text, pos, 1) ' Is the current character allowed? If InStr(1, AllowChars, char) 0 Then ' If so, append it to the new string variable newstr = newstr & char End If Next ' Replace the old value with the new value .Text = newstr End With End Sub -- Regards, Tim Zych http://www.higherdata.com Workbook Compare - Excel data comparison utility "Deen" wrote in message ... Hi, Please see the below coding, This working fine, But is accepting the decimal value also(.), What i required is when ever i type dot(.) it need to show msg "Please Enter Correct Number" Eg:1) 6161.8976, 2)98450.0, 3)8.874 need to show msg "Please Enter Correct Number" and delete the what ever typed that means nullstring in that textbox. Private Sub TextBox11_Change() Worksheets("FOR").Activate Range("C1").Select Range("C1").Value = TextBox11.Value If Not IsNumeric(TextBox11.Value) And TextBox11.Value < vbNullString Then MsgBox "Please Enter Correct Number" TextBox11.Value = vbNullString End If End Sub I'm very newbie for this coding. please anyone can help me on this. Thanks in advance Deen |
All times are GMT +1. The time now is 08:10 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com