How to to to make a textbox appearing as a date ?

francois.lemarie

Board Regular
Joined
Mar 24, 2010
Messages
54
Hello

I want this textbox appear in Date format all the time.

It's a date box with linked cell that will be modified automatically, so a change event it is not possible. The linkedcell X7 is still in date format.

Any way to do it ?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi,

Try using the code below:

Code:
Private Sub TextBox1_Change()
    TextBox1.Value = Format(Range("A2").Value, "MM/DD/YYYY")
End Sub

You will get the desired output. (y)
 
Upvote 0
I see you insisted to put it in a change event. My textbox is linked with a cell in which you have the formula : =today(). User won't change it.
I trew to do what you said but if I changed the system date to update the content of the result =today(), the textbox is not being updated. Indeed, the textbox must be updated automatically when the date is changing.

Please, do you have another solution that will really work in this case ?
 
Last edited:
Upvote 0
Insert a TextBox from the Drawing Toolbar. Select it, go to the formula bar, type =, point at the cell you want to link to and press Enter. When you select the TextBox you should see a formula like =$A$1 in the formula bar.
 
Upvote 0
Hi

The change event will be triggered when the LinkedCell value changes. Using =TODAY() or NOW() is fine.

Code:
[COLOR="Blue"]Private[/COLOR] [COLOR="Blue"]Sub[/COLOR] TextBox1_Change()
    [COLOR="Blue"]With[/COLOR] Me.TextBox1
        .Value = [COLOR="Blue"]Format$[/COLOR](Me.Range(.LinkedCell).Value, "dd/mm/yy")
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0
The response of Jon was more suitable to my needs.

I copied your code Jon and it worked.

However, as Excel does not consider the LinkedCell is changing when it updates today() it automatically, I had then to add to Jon's code a complementary macro to simulate a user is changing the cell.

Private Sub Worksheet_Activate()
Range("x7").Value = "=today()"
Range("A1").Select
End Sub

And thus I could solve my problem.

Thanks to both for your time !

François
 
Upvote 0
However, as Excel does not consider the LinkedCell is changing when it updates today() it automatically, I had then to add to Jon's code a complementary macro to simulate a user is changing the cell.

That's strange because it worked as expected when I tested it. It refreshed with each calculation (test by hitting F9). I don't suppose you're working in manual calculation mode?

But all in all I'm glad you got it working. :)
 
Upvote 0
Yes, That's really strange. Furthermore it stopped working so I trew the pruposition of Andrew and its works.

Thanks to both for your very kind help.

Best regards.
 
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,228
Members
448,951
Latest member
jennlynn

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