1

I have created an Excel that includes a mapping file. What I am trying to do is have users enter the data in here and press ctrl + E (I created a macro) and it would export it out as XML. Here's the issue: When line 1 gets exported, it keeps its date and time format in XML (Example: In XML, time will show up as 12/01/2013). But anything entered under that line will not show up in the format I want. Instead, it will show up as 1345464 for date.

This thing has been very annoying because I cannot figure out what I can do to format the whole Excel document/column so it will show the date and time as text instead of weird number.

Someone please help me out.

1
  • Why is the cell alignment for dates different between your two lines of data? Do you have different formats applied? Commented Jun 14, 2013 at 22:38

3 Answers 3

2

In VBA, use the Format function

date = Format(date, "mm/dd/yyyy")

Then change the format of the cell you store it in:

Cells(row, col).NumberFormat = "@"

(substitute your cell's coordinates for row and col)

Sign up to request clarification or add additional context in comments.

1 Comment

but that would still export out as five digit number though right? I want my date to export out as it is (TEXT). I could use another column and do something like: =TEXT(P2,"MM/DD/YYYY"). But then I would be exporting an extra column. I am not familiar with VBA, but is there a way to do this through VBA so the users do not have to do any extra work? Thanks.
2

I'm no expert but I spent a lot of time trying to figure this out and eventually this code worked for me

Dim eCell as Range

 For Each eCell In Range("O20:P20")
        If Len(eCell.Value) > 0 Then
          eCell.NumberFormat = "@"
          eCell.Value = CDate(eCell.Value)

        End If
    Next

The CDate function converts the serial date back to normal date

Comments

1

Wow I feel stupid! It was easier than I could have ever thought:

Step1: Drag the date that is in start date to the row you will populate data. (Do the same for Enddate column).

enter image description here

Step2: Notice a small square box at the bottom (it appears after following the step1). Expand the square box.

enter image description here

Step3: Choose the option that says: Fill Formatting Only.

enter image description here

Congrats! Now try to enter/paste a date. It should stay in left (text format).

Comments

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.