Export sheet date format not correct

dappy

Board Regular
Joined
Apr 23, 2018
Messages
124
Office Version
  1. 2013
Platform
  1. Windows
Morning folks,

So, i have a sheet that is exported from a workbook using workbook adds, the date format in the workbook is yyyy-mm-dd but the format in the sheet after export is lost and reverts back to general format. is it possible to copy a sheet to a new sheet and keep the format?

thanks in advance

Carl
 
thanks again but there lies the issue, i know how to format a range but i cant see how to add the format string into this

VBA Code:
NewBook.Worksheets("Sheet1").Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
thanks again but there lies the issue, i know how to format a range but i cant see how to add the format string into this
Why do you want to use the Format string?
Note that doing that will convert the value from a date entry to a text one, which can really mess up calculations and sorting.
Most of the time, you just want to change the formatting of the columns.

To get the VBA code to do this, simply:
1. Turn on your Macro Recorder
2. Go to the column(s) you want formatted a certain way, and select them
3. Choose your desired formatting
4. Stop your Macro Recorder.

If you view your recorded code, you will have the VBA code that you need to add to your current code. Usually, you can clean it up a little bit, by getting rid of select statements and combining lines (though it is not necessary to do so).

So if your recorded code looks something like this:
VBA Code:
    Range("C:C,E:E,G:G").Select
    Selection.NumberFormat = "yyyy-mm-dd"
You can simplify it to this:
VBA Code:
    Range("C:C,E:E,G:G").NumberFormat = "yyyy-mm-dd"

Note that the Macro Recorder is a VERY useful too for getting snippets of code, and you should really get used to using it!
 
  • Like
Reactions: ZVI
Upvote 0
Ahhh got it, sorry for being a plum!

Its sorted now, thanks for your help and your patients :D

much appreciated
Carl
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,453
Members
448,967
Latest member
grijken

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