0

in my VBA code I'm saving a variable as string because I need this to be open to text - numbers - date like numbers. I then need to copy this into a table.

When copying the first time the variable stays in text but the second time it goes into number format if the text is something that resembles a date (e.g. "11-2023" gets copied into "45231").

It seems that my variable is saved as "45231" form this point forward.

How can I force the variable value to stay in "11-2023" style?

THX!

I try formatting the column as text, doesn't work.

4
  • 3
    I try formatting the column as text - do that before copying, not after. Commented Mar 4, 2024 at 16:01
  • 1
    ... e.g. ThisWorkbook.Sheets("Sheet1").ListObjects("Table1").ListColumns("ID").DataBodyRange.NumberFormat = "@". Commented Mar 4, 2024 at 16:16
  • Have a look at this answer about dates in Excel too. Commented Mar 5, 2024 at 5:46
  • Welcome Tommaso! Read The Tour and earn your first badge! Commented Mar 5, 2024 at 5:46

0

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.