1

I have 17 columns in my sheet 1 and when I am copying the data in sheet 2 only 13 columns are being pasted with the specified format sheet 2.

In that 17 columns I have date and time stamp. dates below 13 columns are pasted with yyyy-mm-dd hh:mm:ss format and dates which is beyond 13th column are pasted in (if this is the date 2018-03-01 03:00:00) it is pasted as 43160.125.

enter image description here

and the code I have used is

sht1.Cells.Copy
sht2.Range("A1").PasteSpecial xlPasteValues

P.S: I have used NumberFormat too but it's no use.

1
  • Copy and PasteSpecial is a 2- line command. You used 1) sht1.Cells.Copy 2) sht2.Range("A1").PasteSpecial xlPasteValues and 3) sht2.Range("A1").PasteSpecial xlPasteFormats and it didn't work ? Commented Apr 17, 2018 at 13:00

1 Answer 1

1

Try this (Untested)

sht1.Cells.Copy
sht2.Range("A1").PasteSpecial xlPasteFormats
sht2.Range("A1").PasteSpecial xlPasteValues
Application.CutCopyMode = False
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. it worked. Why only xlPasteValues cannot be used. Why do xlpasteFormats need to be used with that. I believe xlPasteValues pastes all the values. So, date and time isn't considered as a value. Is it a format?
Sort of: Dates are held as a long - the number of days since 1/1/1900. To see them in a conventional style such as "Jan 1 1900" you need a format. Similarly hours are held as decimal fractions of 24 hours - so 12 noon = 0.5
@AnkitaRoy: Have a look at this cpearson.com/excel/datetime.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.