RyanB
RyanB

Reputation: 11

How can I display decimals as a percentage while keeping the formulas

I am writing a VBA code for an Excel file that contains formulas to format the design.

I have at rows C10-->J10 a percentage row and the displayed result is a decimal such as 0.32 and I would like to make it show as 32 % while keeping the cell formula that way if I change any value the percentage updates.

So far I have multiplied the cells by 100 and added the % symbol and the values look as I want but the formulas are gone.

Here's what I did:

    For Each Cell In Range("C10:U10")
        Cell.Value = Cell.Value * 100
    Next Cell
    Range("C10:J10").NumberFormat = "##0.00 \%"

Does anyone know if it's possible to do it?

Upvotes: 1

Views: 686

Answers (1)

Pᴇʜ
Pᴇʜ

Reputation: 57683

Don't re-calculate Cell.Value = Cell.Value * 100 just set your number format to

Range("C10:J10").NumberFormat = "0.00 %"   ' will show 0.32 as 32,00 %

or

Range("C10:J10").NumberFormat = "0 %"   ' will show 0.32 as 32 %

The value in the cell will still be 0.32 but it is shown as 32,00 % or 32 % and the formula will stay intact.

Upvotes: 1

Related Questions