Slight modification required

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
688
Hello
Slight modifciation required from below code.
I want to enter the text in textbox with Numeric Values with "-" For eg Date 22-09-2009
what will be the change in the below code to acheive with numeric values and "-"
Code:
   KeyAscii = -KeyAscii * CLng(Chr(KeyAscii) Like "#")
   If KeyAscii = 0 Then Beep

Thanks
NimishK
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
You can try something like this

Code:
Private Sub [COLOR=#ff0000]TextBox2[/COLOR]_Change()
    Dim t As String
    With [COLOR=#ff0000]TextBox2[/COLOR]
        t = .Text
        Select Case Len(t)
            Case 2, 5:          t = t & "-"
            Case Is >= 10:      t = Left(t, 10)
        End Select
        .Text = t
    End With
End Sub

Private Sub [COLOR=#ff0000]TextBox2[/COLOR]_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    With [COLOR=#ff0000]TextBox2[/COLOR]
        Select Case KeyAscii
            Case Asc("0") To Asc("9")
            Case Else: KeyAscii = 0
        End Select
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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