jenna_may17
New Member
- Joined
- Aug 8, 2014
- Messages
- 6
Hi All!
I'm new to VBA so apologies if this is more straightforward than it seems. I have a spreadsheet which is used to automate some report formatting and create graphs for an end user. The end user exports the required reports from our database, pastes them into my workbook and my macro then performs basic minor formatting changes to allow excel to use the data as required and updates existing pivottables & graphs accordingly.
One aspect of the formatting is that our DB exports dates with a space on the end which means Excel won't recognise these as dates. I've been using text to columns with space as the delimiter and simply deleting the second column afterwards-all good and works fine, but only the first time with that data. The first time you run the macro on a data range the dates are left as UK and are fine. If my end user then adds additional data to the end of the existing range, when the macro runs again the text to columns will turn the dates that have already been amended by the macro the first time to American dates (but of course only the ones which work as American dates). I'd prefer the user to be able to simply export the next month's data from the database and add it to the end of the existing range, however if the macro is going to wreck the dates every time you run it more than once on the same data they will have to export the whole year every time. Does anyone have a solution on how I can get VBA to not turn the dates to American? I'm not sure why it's even doing it as it's not actually directly "handling" the dates as such-it's simply splitting the cell contents after the space and excel is set to UK dates.
Below is the code I'm using to split the columns with the date, essentially simply inserting a blank column after the date column, splitting the date using the "space" delimiter, then deleting the column with the spaces removed.
Any help appreciated! Thanks
I'm new to VBA so apologies if this is more straightforward than it seems. I have a spreadsheet which is used to automate some report formatting and create graphs for an end user. The end user exports the required reports from our database, pastes them into my workbook and my macro then performs basic minor formatting changes to allow excel to use the data as required and updates existing pivottables & graphs accordingly.
One aspect of the formatting is that our DB exports dates with a space on the end which means Excel won't recognise these as dates. I've been using text to columns with space as the delimiter and simply deleting the second column afterwards-all good and works fine, but only the first time with that data. The first time you run the macro on a data range the dates are left as UK and are fine. If my end user then adds additional data to the end of the existing range, when the macro runs again the text to columns will turn the dates that have already been amended by the macro the first time to American dates (but of course only the ones which work as American dates). I'd prefer the user to be able to simply export the next month's data from the database and add it to the end of the existing range, however if the macro is going to wreck the dates every time you run it more than once on the same data they will have to export the whole year every time. Does anyone have a solution on how I can get VBA to not turn the dates to American? I'm not sure why it's even doing it as it's not actually directly "handling" the dates as such-it's simply splitting the cell contents after the space and excel is set to UK dates.
Below is the code I'm using to split the columns with the date, essentially simply inserting a blank column after the date column, splitting the date using the "space" delimiter, then deleting the column with the spaces removed.
Code:
Columns("D:D").Select
Selection.Insert Shift:=xlToRight
Columns("C:C").Select
Selection.TextToColumns Destination:=Range("C1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False, OtherChar _
:="/", FieldInfo:=Array(1, 4), TrailingMinusNumbers:=True
Columns("D:D").Select
Selection.Delete Shift:=xlToLeft
Any help appreciated! Thanks
Last edited: