Guinaba
Board Regular
- Joined
- Sep 19, 2018
- Messages
- 233
- Office Version
- 2016
- Platform
- Windows
Hi guys,
The code below is copying the data from a table (listobject) and saving in another file (csv), however not sure why the first colum which is date format (dd/mm/yyyy) is getting changed to mm/dd/yyyy when the sub is writing in the csv file. Is there a way to avoid that?
Cheers
The code below is copying the data from a table (listobject) and saving in another file (csv), however not sure why the first colum which is date format (dd/mm/yyyy) is getting changed to mm/dd/yyyy when the sub is writing in the csv file. Is there a way to avoid that?
Cheers
VBA Code:
Sub PlannedOrdersHistory()
Application.ScreenUpdating = False
Dim CurrDate As Date
CurrDate = Date
Dim CurrFileName As String
CurrFileName = Format(CurrDate, "yyyymmdd") & "_ED_Fcst_VS_Planned_Orders_V10" & ".XLSM"
Dim Wb1 As Workbook: Set Wb1 = Workbooks(CurrFileName)
Dim Wb2 As Workbook: Set Wb2 = Workbooks.Open("C:\Users\gnassifb\OneDrive - Lion Pty Ltd\Documents\ED\ED Planned Orders\ED_Planned_Orders_History_1.csv")
Dim LRow As Integer
Dim SearchString As String
Dim SearchRange As Range
SearchString = CurrDate
With Wb2.Worksheets("ED_Planned_Orders_History_1")
'Find the last non-blank cell in column A(1)
LRow = .Cells(Rows.Count, 1).End(xlUp).Row
End With
'Check if the data is already copied
Set SearchRange = Range("A2:A" & LRow).Find(SearchString, LookIn:=xlValues, lookat:=xlWhole)
If SearchRange Is Nothing Then
Wb1.Worksheets("EDPlannedOrders").ListObjects("tPlannedOrdersWeekly").DataBodyRange.Copy _
Destination:=Wb2.Worksheets("ED_Planned_Orders_History_1").Range("A" & LRow)
Else
MsgBox "Data is already copied", vbExclamation: Exit Sub
End If
'Wb2.Close SaveChanges:=True
End Sub