date text field copied

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Date in a text field copied wrongly into destination file (month

Date in a text field copied wrongly into destination file (month

resolvedResolved · Medium Priority · Version 2010

Susanna has attended:
Excel VBA Intro Intermediate course
Taking Minutes course
Excel VBA Advanced course
Excel PowerPivot course

Date in a text field copied wrongly into destination file (month

I have dates in an array, to be moved to destination file. These dates are characters, and when I move them to final file, the month becomes the day and the day becomes the month, that is:
"01/07/2015" goes into the final file as
07/01/2015

I've tried various things, being the last one Dateserial funtion, but I still get the wrong data:

Dim vConvDate As Date

vConvDate = DateSerial(Val(Year(vWorkTable(i, Val(j)))), Val(Month(vWorkTable(i, Val(j)))), Val(Day(vWorkTable(i, Val(j)))))
Cells(vIndex, vColDB) = vConvDate

Can you please tell me what is the problem?

Thank you very much

RE: Date in a text field copied wrongly into destination file (m

Hi Susanna,

Thank you for the forum question.

Yes date formats can be a complicated thing to get right in Excel. I have had many questions about date formatting.

Many times when we import data from external data source we have the problem also sometimes when it is internal data.

Can I ask you to try the code below where the only thing you need to amend is the range. In my code I reformat column A.


Sub dateformat()

Dim c As Range
For Each c In ActiveSheet.UsedRange.Columns("a").Cells
c.Value = DateValue(c.Value)
Next c
End Sub

If it is not doing the job please let me know.



Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Date in a text field copied wrongly into destination file (m

Hi Jens,

sorry for the delay in checking it!

I have tried what you suggested and it does not work either.

Kind regards,
Susanna

Mon 27 Jul 2015: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Using the Quick Access Toolbar in Excel2010

The Quick Access Toolbar is included in virtually every Office product, including Outlook 2010, Word 2010, Excel 2010, and PowerPoint 2010.

You will find the Quick Access Toolbar in the top-left side of the window. To begin, click the Customize button (it's the little black arrow at the end of the toolbar).

Simply click the commands you want to include.

Virtually any command can be added to the Quick Access Toolbar. Click the More Commands option and a new window will open from where you can browse the commands including those not on the ribbon.

View all Excel hints and tips


Server loaded in 0.07 secs.