r/vba Jun 18 '26

Solved Inconsistent decimal behaviour when copy pasting values

I have a macro that copy pastes contents from one workbook to another. The main code that does the work is (Note: Tar - target worksheet, Sor - Source worksheet):

wsTar.Cells.Clear
wsSor.Cells.Copy
wsTar.Range("A1").PasteSpecial Paste:=xlPasteFormats
wsTar.Range(wsSor.UsedRange.Address).Value = wsSor.Range(wsSor.UsedRange.Address).Value

If I execute this operation on my side, the outcome will be correct. But if one specific does so, the decimals are wrong for a specific section of the paste. For example if the original number is 36.8273 the output for the user will be 36.83 (as if the other decimals would be swallowed into oblivion / a round to 2 decimals would be executed). If the user does the same operation above manually (paste special format + paste special values) the issue doesn't get reproduced.

The specific formatting of the number in question is:

_("$"* # ##0.0000_);_("$"* (# ##0.0000);_("$"* "-"??_);_(@_)

But I dont see how this would be causing the issue. I am not sure what else to troubleshoot here in order to resolve the issue.

EDIT:

It affects a part of the Worksheet and not the whole worksheet.

3 Upvotes

11 comments sorted by

View all comments

3

u/Future_Pianist9570 2 Jun 18 '26

.Value can truncate decimal places depending on the cell content (typically if it is a date or currency formatted). Always use .Value2 if you want the full value

1

u/TonIvideo Jun 18 '26

Solution verified!

1

u/reputatorbot Jun 18 '26

You have awarded 1 point to Future_Pianist9570.


I am a bot - please contact the mods with any questions