Transposing date when transferring textbox data to sheet

RockEd

Board Regular
Joined
Aug 13, 2021
Messages
80
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a relatively simple userform to enter data into the worksheet.

One of textboxes is a textbox where the user needs to enter a date; unfortunately it seems to be transposing part of the date (seems like converting from a UK to a US date).

The condensed code is this:

VBA Code:
    With shData
        .Cells(newRow, Date1stmeeting).Value = TextBox3.Value
    End With

So if I enter 11/08/2021 into the textbox, the cell on the sheet will show 08/11/2021 (if it's not obvious - I don't want this to happen...I want to enter a UK date and see a UK date on the sheet..).

The format of the cell shows it as the 'date' in the United Kingdom...

The funny thing is if you enter a date like 15/11/2021, then the date will still show as 15/11/2021.

Any ideas on how to solve this one?

thanks
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Don't rely on VBA's implicitness, so change that line of code like ...

VBA Code:
.Cells(newRow, Date1stmeeting).Value = CDate(TextBox3.Value)

EDIT:
Note that this code will error if this text box contains a text which cannot be converted to a date.
 
Upvote 0
Solution
Perfect - thank you!

I added a bit of error handling to alert the user where they enter an invalid date.

Where optionbutton5 enables the 1st meeting date textbox field...

VBA Code:
            If OptionButton5 = True Then
                If IsDate(TextBox3.Text) Then
                .Cells(newRow, Date1stmeeting).Value = CDate(TextBox3.Value)
                Else
                MsgBox ("You did not enter a valid date in the 1st meeting date field, please enter this manually on the worksheet"), vbCritical + vbOKOnly
                End If
            End If
 
Upvote 0
You're welcome. Note that using VBA's IsDate function does not necessarily prevent you from input errors.
For example, if accidentally "11/13/21" is entered where "11/12/21" (December 11th) was intended, VBA still transforms the date to November 13th.
 
Upvote 0

Forum statistics

Threads
1,215,009
Messages
6,122,674
Members
449,091
Latest member
peppernaut

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