Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88030

Excel vba - Format isn't copied to other cell

$
0
0

I got an excel file with an autoincrement on 1 cell, where the numberformat is "000".

Worksheets("TEST").Range("M17").Value = Worksheets("TEST").Range("M17").Value + 1
Worksheets("TEST").Range("M17").NumberFormat = "000"

This works fine, so my first number is: 001 instead of 1.

Now I need to merge this cell to another cell M16 (which displays an input for example: 2020)

=M16&"/"&M17

But for some reason it is losing his NumberFormat, and excel is showing: 2020/1 instead of 2020/001.

I have tried several things, like formatting my cell M18

Worksheets("TEST").Range("M18").NumberFormat = "0000/000"

Or by trying to solve this directly in vba

Worksheets("TEST").Range("M18").Value = Worksheets("FACTUUR").Range("M16").Value & Worksheets("TEST").Range("M17").Value
Worksheets("TEST").Range("M18").NumberFormat = "0000/000"

Or even by changing the format from within Excel itself, but then I get an error message directly (don't know why...)

enter image description here

Any idea on how to solve this?


Viewing all articles
Browse latest Browse all 88030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>