简体   繁体   中英

Decimal point getting ignored in excel vba

I have a macro running on excel which copies a number from one sheet to the other

First I store all the relevant numbers in a string array va() and than assign the array values in the new sheet.

ActiveCell.Offset(0, 5).Value = va(i, 5)

when number is -0,522004, I get the correct result in the new sheet, however when the number is -1,175378 I get -1175378,0000 as output in the excel sheet.

Note that I am using "," as decimal separator and "." as thousand separator.

I also tried to put msgbox va(i,5) and it shows -1,175378 as output but when the code is complete I get decimal ignored values.

假设您的区域设置与字符串数据匹配(即逗号是小数点分隔符),则可以执行显式强制:

ActiveCell.Offset(0, 5).Value = CDbl(va(i, 5))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM