Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Detect Prcentage Format in a Cell

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Detect Prcentage Format in a Cell

Hi Chris,

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

--
Kind regards,

Niek Otten

"Chris Gorham" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Detect Prcentage Format in a Cell

Make that

Debug.Print Range("a1").NumberFormat

--
Kind regards,

Niek Otten

"Niek Otten" wrote in message
...
Hi Chris,

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

--
Kind regards,

Niek Otten

"Chris Gorham" wrote in message
...
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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Detect Prcentage Format in a Cell

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

--
Regards,
Tom Ogilvy


"Chris Gorham" wrote in message
...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Detect Cell Colour MayJuneJuly Charts and Charting in Excel 1 July 22nd 08 09:56 PM
Date Auto-detect & format Issues uw805 Excel Discussion (Misc queries) 2 April 17th 07 07:42 AM
prcentage of hours lee Davies Excel Discussion (Misc queries) 1 January 10th 06 04:21 PM
How to detect if a cell is formula Frank Kabel Excel Programming 0 May 24th 04 07:48 AM
Detect if conditional format is true Bill[_21_] Excel Programming 5 March 4th 04 04:53 PM


All times are GMT +1. The time now is 08:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"