Detect Prcentage Format in a Cell

G

Guest

Hi,

I want to be able to detect the format of a formula or value in a cell and
particularly if it has percentage format.

I can't find a clever VBA statement to detect the cell format so I thought
about testing the cell value using "Instr" to see if the "%" was the last
character in the string. However when I write a VBA statement to test the
variable it restates the value of the cell from %'s to a decimal (e.g. 5%
becomes 0.05) thus eliminating the % sign I'm attempting to detect...

Ideas most welcome...Chris
 
N

Niek Otten

Make that

Debug.Print Range("a1").NumberFormat

--
Kind regards,

Niek Otten

Niek Otten said:
Hi Chris,

Use the NumberFormat property,
like in
dbug.print[a1].numberformat

--
Kind regards,

Niek Otten

Chris Gorham said:
Hi,

I want to be able to detect the format of a formula or value in a cell
and
particularly if it has percentage format.

I can't find a clever VBA statement to detect the cell format so I
thought
about testing the cell value using "Instr" to see if the "%" was the last
character in the string. However when I write a VBA statement to test the
variable it restates the value of the cell from %'s to a decimal (e.g. 5%
becomes 0.05) thus eliminating the % sign I'm attempting to detect...

Ideas most welcome...Chris
 
T

Tom Ogilvy

As Niek said, you can use the numberformat property which is probably the
best approach. If you know there will be a value in the cell, then you
could use the Text property which provides a string representation of how
the cell appears or displays its value.

If right(activeCell.Text,1) = "%" then

or

If Instr(1,Activecell.Text,"%",vbTextcompare) then
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top