Jake Peralta
New Member
- Joined
- Jun 9, 2020
- Messages
- 9
- Office Version
- 2010
- Platform
- Windows
Hi all,
First time posting on a message board.. I have done an exhaustive search on this issue (literally been working on this since 8pm last night and it is now about 7am here) to no avail, which has led me here. I'm experiencing a common problem that a lot of people encounter when using VBA to copy and paste dates between workbooks, whereby 'ambiguous dates' in AUS/UK format such as 07/12/2020 get converted to US format i.e. 12/07/2020. To save time for those kindly assisting, I have tried countless fixes and here's what I have ruled out:
1. I've ensured my Windows regional settings are set to my region (Australia) with short date set to how I would like to see it ("dd/mm/yyyy")
2. I've done a full scale trial and error with Transition Formula Entry ("TFE") checked and unchecked between the source workbook and the destination workbook. Closest bet is to go with TFE checked in the destination workbook but then it doesn't register as a date (when I filter by date I get years grouped together for entries that were done before I had selected the TFE, but after this I get what look like dates but are not grouped within the relevant years and don't appear when I filter by a date range).
3. I've tried workarounds such as thinking perhaps I could concatenate with an apostrophe from the source workbook and then do a find and replace to remove it once in the destination workbook which didn't work, so I tried trim but this didn't work either - I just got a numerical string which doesn't convert to a date
4. I've tried Text to Columns but all my dates then just convert to 01/01/1900 or decimals depending on the settings (General, Text, Date etc)
5. I've tried setting the date format for export (and also the destination formatting) to multiple settings, including yyyy-mm-dd which I'd read had worked for some people and finally;
6. I've also tried inserting things into the code that I've found re changing formats to local etc but nothing seems to work although I feel like this is the most likely route for success.
I am very much a hack when it comes to VBA, I have literally cobbled together bits of code from all over in order to achieve what I wanted to without really understanding too many of the basics which is where things like this become a bit of a problem. Here is my code (I've posted the whole thing but the relevant part for exporting to the Master File is after the 'RDB code starts again' comment, and the specific source cell with the date in it is ThisWorkbook.Sheets("Import Export").Range("H10"):
As I said, I'm very much a hack so the code above is probably highly inefficient and I've just done it all by trial and error to get it functioning properly, which it does, but the one thing I can't figure out is these dates. Any help on this would be greatly appreciated, thank you.
First time posting on a message board.. I have done an exhaustive search on this issue (literally been working on this since 8pm last night and it is now about 7am here) to no avail, which has led me here. I'm experiencing a common problem that a lot of people encounter when using VBA to copy and paste dates between workbooks, whereby 'ambiguous dates' in AUS/UK format such as 07/12/2020 get converted to US format i.e. 12/07/2020. To save time for those kindly assisting, I have tried countless fixes and here's what I have ruled out:
1. I've ensured my Windows regional settings are set to my region (Australia) with short date set to how I would like to see it ("dd/mm/yyyy")
2. I've done a full scale trial and error with Transition Formula Entry ("TFE") checked and unchecked between the source workbook and the destination workbook. Closest bet is to go with TFE checked in the destination workbook but then it doesn't register as a date (when I filter by date I get years grouped together for entries that were done before I had selected the TFE, but after this I get what look like dates but are not grouped within the relevant years and don't appear when I filter by a date range).
3. I've tried workarounds such as thinking perhaps I could concatenate with an apostrophe from the source workbook and then do a find and replace to remove it once in the destination workbook which didn't work, so I tried trim but this didn't work either - I just got a numerical string which doesn't convert to a date
4. I've tried Text to Columns but all my dates then just convert to 01/01/1900 or decimals depending on the settings (General, Text, Date etc)
5. I've tried setting the date format for export (and also the destination formatting) to multiple settings, including yyyy-mm-dd which I'd read had worked for some people and finally;
6. I've also tried inserting things into the code that I've found re changing formats to local etc but nothing seems to work although I feel like this is the most likely route for success.
I am very much a hack when it comes to VBA, I have literally cobbled together bits of code from all over in order to achieve what I wanted to without really understanding too many of the basics which is where things like this become a bit of a problem. Here is my code (I've posted the whole thing but the relevant part for exporting to the Master File is after the 'RDB code starts again' comment, and the specific source cell with the date in it is ThisWorkbook.Sheets("Import Export").Range("H10"):
VBA Code:
Option Explicit
Sub UpdateTasks2()
Dim LRow As Long, i As Long
Dim varData As Variant
Dim c As Range
Dim Worksheet As Worksheet
Dim SourceRange As Range
Dim DestRange As Range
Dim DestWB As Workbook
Dim DestSh As Worksheet
Dim Lr As Long
'From here RDB Code'
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'Inserted my code here. Checks if an authorised user has removed data validation and put in another authorised approver's name
With ThisWorkbook.Sheets("Template").Range("F7").Validation
If Range("F7").Validation.ShowError = False Then
MsgBox "You have removed the data validation error alert on the Authorised Approver cell. Please re-apply it for data to be saved.", vbCritical
Range("F7").ClearContents
Range("Copy5").Copy
Range("DATA5").PasteSpecial xlPasteFormulas
Exit Sub
Else
End If
End With
If ThisWorkbook.Sheets("Lookups").Range("PreventExport") = "Yes" Then
MsgBox "You are attempting to change data that has already been finalised. It is now read only and cannot be amended.", vbCritical
Range("Copy1").Copy
Range("DATA1").PasteSpecial xlPasteFormulas
Range("Copy2").Copy
Range("DATA2").PasteSpecial xlPasteFormulas
Range("Copy3").Copy
Range("DATA3").PasteSpecial xlPasteFormulas
Range("Copy4").Copy
Range("DATA4").PasteSpecial xlPasteFormulas
Range("Copy5").Copy
Range("DATA5").PasteSpecial xlPasteFormulas
Range("Copy6").Copy
Range("DATA6").PasteSpecial xlPasteFormulas
Exit Sub
End If
'RDB Code starts again
If bIsBookOpen_RB("Master File.xlsm") Then
Set DestWB = Workbooks("Master File.xlsm")
Else
Set DestWB = Workbooks.Open("C:\Users\pat\Desktop\Spreadsheets\Master File.xlsm")
End If
'RDB Code finishes here.
Set SourceRange = ThisWorkbook.Sheets("Import Export").Range("B10:H10")
With ThisWorkbook.Sheets("Import Export")
LRow = .Cells(Rows.Count, 1).End(xlUp).Row
varData = .Range("B10:H10" & LRow)
End With
With DestWB.Sheets("Master Data")
For i = LBound(varData) To UBound(varData)
Set c = .Range("B:B").Find(varData(i, 1), LookIn:=xlValues, LookAt:=xlWhole)
If c Is Nothing Then
.Cells(Rows.Count, 2).End(xlUp)(2).Resize(1, UBound(varData, 2)) _
= Application.Index(varData, i)
Else
.Cells(c.Row, 2).Resize(1, UBound(varData, 2)) _
= Application.Index(varData, i)
End If
Next
End With
DestWB.Close savechanges:=True
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox ("Master File has been updated")
Range("NewEntryLookup").Copy
Range("EntryNumber").PasteSpecial xlPasteValues
Range("DATA1").ClearContents
Range("DATA2").ClearContents
Range("DATA3").ClearContents
Range("DATA4").ClearContents
Range("DATA6").ClearContents
If Range("AuthorityLevel") = 1 Then
Range("DATA5").ClearContents
If Range("AuthorityLevel") <> 1 Then
If Worksheet.ProtectContents = True Then
Worksheet.Unprotect Password:="M!chael"
Range("DATA5").ClearContents
Worksheet.Protect Password:="M!chael"
End If
End If
End If
End Sub
'Code Sources (combination of the below, with my edits)
'https://www.mrexcel.com/board/threads/update-a-master-sheet-with-changed-or-new-data-from-another-sheet.935174/page-2
'https://www.rondebruin.nl/win/s3/win001.htm
As I said, I'm very much a hack so the code above is probably highly inefficient and I've just done it all by trial and error to get it functioning properly, which it does, but the one thing I can't figure out is these dates. Any help on this would be greatly appreciated, thank you.