Date from userform pasted in the wrong format

35 Views Asked by At

I have a userform which is used to collect data in excel by pasting the data from the userform into excel.

This issue that im encountering is that upon pasting the date from TXT_DateLogged, which is displayed in the userform textbox as dd/mm/yy. excel is changing it to MM/DD/YYYY.

The routines involved i have listed below:

Private Sub UserForm_Initialize()
    Me.Height = 432
    Me.Width = 438
    Me.Zoom = 100

    Txt_DateLogged.Value = Format(Date, "dd/mm/yyyy")
    Txt_Month.Value = Format(Date, "MMM-YY")

    Call CBO_Supplier_Items
    Call CBO_SRM_Items
    Call CBO_Cause_Items
    Call CBO_Categorisation_Items

    Dim wsLog As Worksheet
    Dim wsArchive As Worksheet
    Dim i As Long
    Dim maxIssueNum As Long

    ' Set references to the "LSI Log" and "LSI Archive" sheets
    Set wsLog = ThisWorkbook.Sheets("LSI Log")
    Set wsArchive = ThisWorkbook.Sheets("LSI Archive")

    ' Find the maximum LSI-## in "LSI Log"
    i = wsLog.Cells(wsLog.Rows.Count, 1).End(xlUp).Row
    maxIssueNum = GetMaxIssueNumber(wsLog, i)

    ' Find the maximum LSI-## in "LSI Archive"
    i = wsArchive.Cells(wsArchive.Rows.Count, 1).End(xlUp).Row
    maxIssueNum = Application.WorksheetFunction.Max(maxIssueNum, GetMaxIssueNumber(wsArchive, i))

    ' Set the next available LSI-## in the textbox
    Me.Txt_IssueNum.Value = "LSI-" & Format(maxIssueNum + 1, "00")

End Sub 
Sub Btn_Submit_Click()
 
    Dim rw As Integer
    Dim ref As String
    Dim refnum As Integer
    Dim ws As Worksheet
    Set ws = Sheets("LSI Log")
    
    'Find the last row in the sheet
    rw = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1
    
    'Insert data into sheet
    
    ws.Cells(rw, 1).Value = Txt_IssueNum.Value
    ws.Cells(rw, 2).Value = CBO_LA_OOA.Value
    ws.Cells(rw, 3).Value = Txt_Month.Value
    ws.Cells(rw, 4).Value = Txt_DateLogged.Value
    ws.Cells(rw, 5).Value = CBO_SRM.Value
    ws.Cells(rw, 6).Value = CBO_Supplier.Value
    ws.Cells(rw, 7).Value = Txt_Description.Value
    ws.Cells(rw, 8).Value = Cbo_Cause.Value
    ws.Cells(rw, 9).Value = Txt_CauseReason.Value
    ws.Cells(rw, 10).Value = Txt_Impact.Value
    ws.Cells(rw, 11).Value = Txt_NoOfCharges.Value
    ws.Cells(rw, 12).Value = Txt_NoOfSearches.Value
    ws.Cells(rw, 13).Value = Txt_MatrixScore.Value
    ws.Cells(rw, 14).Value = Cbo_Categorisation.Value

    
Unload Me

I have also tried different variations on the Btn_Submit routine being:

ws.Cells(rw, 4).Value = DateValue(Txt_DateLogged.Value)
ws.Cells(rw, 4).NumberFormat = "dd/mm/yyyy"

and

ws.Cells(rw, 4).Value = Format(Txt_DateLogged.Value, "DD/MM/YYYY")

all of which unsuccesfull and still pasting in the MM/DD/YYYY format.

any thoughts as to where its failing or any possible solutions?

0

There are 0 best solutions below