简体   繁体   中英

Remove decimal by VBA from a cell in Excel 2010

I wrote a code by VBA for removing decimal from a cell (A22) But it doesn't work.

Range("A22").Text = Format(Range("A22").Text, "#,###,###,##0")

may something is wrong. Any idea is welcome.

尝试这个

Range("A1").Value = Format(Range("A1").Text, "#,###,###,##0")

NumberFormat vs Format

If you are trying to display the value in cell A22 without decimals:

Range("A22").NumberFormat = "#,##0"

The cell will still contain the value with decimals, it will only be displayed without.


If you are trying to remove the decimals from the value in cell A22 :

Range("A22") = Int(Range("A22"))

Now the cell contains the value without the decimals (a whole number).

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