0

Excel changes the following values automatically to a number, I guess because he considers them as a date:

2/2/1 becomes 36527 4/2/1 becomes 36926

I have a column with a combination of different formats now:

2/1/
3/1/
8/7/
36527
1/0/0
36926

Which VBA code can I use to convert the numbers back to their original format? The other values should stay the same.

I know the cDate function, but I guess it's not useful here?

I have already this in my VBA code for pasting values

ActiveWorkbook.Sheets("Import").Columns("A:AH").NumberFormat = "@"
ActiveWorkbook.Sheets("Import").Range("A1").Select
ActiveSheet.Paste

1
  • 2
    before importing or inputting the values, change the cells to text. Excel will then not change them to dates. Commented Mar 18, 2020 at 15:34

1 Answer 1

1

You can't change them back. Once Excel converts them, the original value is gone. Before you input the value, you can prepend an apostrophe to force it to text.

ActiveCell.Value = "'" & sMyValue

or as @Scott Craner commented, you can format the cell as text

ActiveCell.NumberFormat = "@"
ActiveCell.Value = sMyValue
Sign up to request clarification or add additional context in comments.

2 Comments

I had already this in my VBA code ActiveWorkbook.Sheets("Import").Columns("A:AH").NumberFormat = "@" ActiveWorkbook.Sheets("Import").Range("A1").Select ActiveSheet.Paste
If you paste, it will overwrite the formatting. It's best to set the Value property rather than paste. But if the value you need is only in the clipboard, then paste special so you don't overwrite the formatting.

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.