fill Date "dd/mm/yyyy" in textboxes automatically when just write day

Abdo

Board Regular
Joined
May 16, 2022
Messages
183
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hi
I want when write day of date ,then will fill the current month & current year automatically without I enter manually .
for instance if I have textbox1 on userform , and write day "23" then will fill automatically like this 23/01/2023
I have this but is useless
VBA Code:
Private Sub TextBox1_Change()
TextBox1.Text = Format(TextBox1.Text, "dd/mm/yyyy")
End Sub
I hope this is sens .
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Sub AutoFillMonthYear()
Dim dateStr As String
dateStr = Range("textbox1").Value
Range("textbox1").Value = dateStr & "/" & Month(Date) & "/" & Year(Date)
End Sub

This code should be placed in the worksheet of the workbook and assigned to the textbox1 control so that it runs whenever the user enters in the day.
 
Upvote 0
thanks
gives error method range of object global failed in this line
VBA Code:
dateStr = Range("textbox1").Value
 
Upvote 0
VBA Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If IsNumeric(TextBox1.Value) Then
        TextBox1.Value = TextBox1.Value & "/" & Format(Date, "MM/yyyy")
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,385
Messages
6,119,210
Members
448,874
Latest member
b1step2far

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