Userform date as string instead of date

Shancer

New Member
Joined
Sep 16, 2021
Messages
2
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello kind community!

I have a userform which contains a textbox for the user to enter a date. I have it so that current day's date automatically populates in the textbox. Then when a command button is clicked, a new row is added with the date in the spreadsheet.

The formatting is correct as I want it ("mm/dd/yyyy"); however when I press "Cntrl + `" I can see that the data appears to be as a string, instead of the numerical values.

My truncated code is as follows:
-------------------------------------------
Private Sub UserForm_Initialize()

With Data_GUI.date1

Me.date1.Value = Format(Now(), "Short Date")

End With

End Sub
--------------------------------------------
Private Sub loadbutton_Click()

Dim NextRow As Long

NextRow = Application.WorksheetFunction.CountA(Range("$A$3:$A$100000")) + 1

Sheets("TEST").Range("Data_Start").Offset(NextRow + 1, 0).Value = date1

MsgBox "Data Successfully Added!", 0, "Complete"

Call resetForm

End Sub
--------------------------------------------

To my understanding, UserForm textboxes appear as a string format; so I may need to do an AfterUpdate format change? Perhaps with Cdate function?

Can someone help me with this? I apologize if this has been answered already. I've searched fairly hard on this forum and other online sources and have not been able to figure it out.

Any help here is greatly appreciated.

Thank you!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Unless you also want error checking code, you don't want to just use cdate on your output line ?
VBA Code:
Sheets("TEST").Range("Data_Start").Offset(NextRow + 1, 0).Value = CDate(date1[)/CODE]
 
Upvote 0
Solution
Unless you also want error checking code, you don't want to just use cdate on your output line ?
VBA Code:
Sheets("TEST").Range("Data_Start").Offset(NextRow + 1, 0).Value = CDate(date1[)/CODE]

Wow - simple as that! It always is - thank you Alex this helps. I do not need to validate the output line.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

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