Making a TextBox date read as a dateMe.

mharper90

Board Regular
Joined
May 28, 2013
Messages
117
Office Version
  1. 365
Platform
  1. MacOS
I have a snippet of code below that is supposed to compare the date entered in TextBox4 with a reference date in TextBox16. If the two match, then it makes TextBox4 blank (this reduced clutter on a worksheet with mostly the same dates).

My problem is that if "5/15/19" is entered into TextBox4, it doesn't find that equal to "5/15/2019" in TextBox16, yet as soon as the Userform is closed, the value transcribed onto the worksheet by TextBox4 ends up being "5/15/2019". Can anyone help me get any valid date (mm/dd/yy, mm/dd/yyyy, dd-mmm-yy, etc) entered in TextBox4 to be compared in the same format that TextBox16 uses (mm/dd/yyyy)?

Code:
If Me.TextBox4.Value = Me.TextBox16.Value Then
     Me.TextBox4.Value = ""
End If
Selection.Offset(0, 2).Value = Me.TextBox4.Value
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi

try

Code:
With Me.TextBox4
        If DateValue(.Value) = DateValue(Me.TextBox16.Value) Then .Value = ""
        Selection.Offset(0, 2).Value = .Value
    End With

Dave
 
Upvote 0
This any good?

Code:
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    
    'Dim dDate As Date
    dDate = DateSerial(Year(Date), Month(Date), Day(Date))
    TextBox4.Value = Format(TextBox4.Value, "dd/mm/yyyy")
    dDate = TextBox4.Value [COLOR=#252C2F][FONT=Courier]End Sub[/FONT][/COLOR]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

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