Saving Dates from User Form to table

FlashNZ

New Member
Joined
Mar 3, 2021
Messages
29
Office Version
  1. 365
Platform
  1. Windows
Hi, I have a simple User Form where I want to save some data into a table in excel. The UF has a date field on it using a Date Picker.

Trouble is when the date is saved to the table it switches the date selected from 1/4/2023 (dd/mm/yyyy) to 4/1/2023 (mm/dd/yyyy) format.

How do I get it to save the date in the correct format (dd/mm/yyyy)?

Code is:
VBA Code:
Private Sub cmdAdd_Click()

Dim Salesperson As String
Salesperson = TextBox1.Text

Dim DatefstSale As String
DatefstSale = DTPicker1


Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Active Table")

Set tbl = ws.ListObjects("Ann_BDListings")

Dim lRow As ListRow
Set lRow = tbl.ListRows.Add

With lRow
.Range(1) = Salesperson
.Range(7) = DatefstSale


End With

End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hello.
I would imagine that DatefstSale must be a textBox.
When you take its value to a cell you must do it like this:

VBA Code:
.Range(7) = CDate(DatefstSale)
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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