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 ?
 

Some videos you may like

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

nchavan

New Member
Joined
Mar 29, 2010
Messages
33
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)
 

francois.lemarie

Board Regular
Joined
Mar 24, 2010
Messages
54
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:

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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.
 

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,808
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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]
 

francois.lemarie

Board Regular
Joined
Mar 24, 2010
Messages
54
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
 

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,808
Office Version
  1. 365
Platform
  1. Windows
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. :)
 

francois.lemarie

Board Regular
Joined
Mar 24, 2010
Messages
54
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,288
Messages
5,600,746
Members
414,405
Latest member
Zaurb

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
Top