Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ALV ALV is offline
external usenet poster
 
Posts: 12
Default Determine format type from strings

Does anyone know if there is an easy or automated way to take a format string
for a numeric cell and determine if it's an Int, Float (with num decimals),
Date, or Time?

Right now we are using a large switch, but there are always new formats that
fall through and end up with the wrong type.

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Determine format type from strings

Hi ALV,

Not quite sure what you mean. A numeric cell has a value, say 39113.542130787
The Numberformat for this cell only determins how this number is to be
displayed on the sheet, but it does not change the value itself. The format
is related to the meaning of the value. My example could mena today's date
and time, or my bank balance (not really) and I would format it accordingly.

It appears you want to go the other way. You expect the format of a cell to
indicate the meaning of the value, which could work (depending on the source
of the data) but only if the few standard formats are being used. As soon as
a cell is formatted with a Custom-format, which by definition is flexible,
there will always be new formats.

Not sure what you mean by integer (no decimals displayed?) or float
(scientific?).

Do you mean the type of a variable? This could be interger. If so, see
vartype in VBA help.



--
Gerd


"ALV" wrote:

Does anyone know if there is an easy or automated way to take a format string
for a numeric cell and determine if it's an Int, Float (with num decimals),
Date, or Time?

Right now we are using a large switch, but there are always new formats that
fall through and end up with the wrong type.

Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Determine format type from strings

Number as stored as doubles in Excel. How they are display is determined by
the NumberFormat property.
Not sure what you are after, but maybe one/some of these will be useful.

Range("A1").Value = 123
Debug.Print VarType(Range("A1").Value)
Debug.Print TypeName(Range("A1").Value)
Debug.Print Range("A1").Text
Debug.Print Range("A1").NumberFormat

NickHK

"ALV" wrote in message
...
Does anyone know if there is an easy or automated way to take a format

string
for a numeric cell and determine if it's an Int, Float (with num

decimals),
Date, or Time?

Right now we are using a large switch, but there are always new formats

that
fall through and end up with the wrong type.

Thanks.



  #4   Report Post  
Posted to microsoft.public.excel.programming
ALV ALV is offline
external usenet poster
 
Posts: 12
Default Determine format type from strings

I should have been more specific...we are converting data to export to
another app which has its own set of data types.

So we want to determine if the Excel user intends for each cell to show as a
Time, Date, Int, Float, Dollar, or Percent.

I was wondering if you can take a FormatString and easily determine if it is
one of those.

"NickHK" wrote:

Number as stored as doubles in Excel. How they are display is determined by
the NumberFormat property.
Not sure what you are after, but maybe one/some of these will be useful.

Range("A1").Value = 123
Debug.Print VarType(Range("A1").Value)
Debug.Print TypeName(Range("A1").Value)
Debug.Print Range("A1").Text
Debug.Print Range("A1").NumberFormat

NickHK

"ALV" wrote in message
...
Does anyone know if there is an easy or automated way to take a format

string
for a numeric cell and determine if it's an Int, Float (with num

decimals),
Date, or Time?

Right now we are using a large switch, but there are always new formats

that
fall through and end up with the wrong type.

Thanks.




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
using a row filled with strings to determine cell value NebJoel Excel Discussion (Misc queries) 5 February 7th 09 04:35 AM
Routine with fuzzy logic to determine the relative comparison of two strings? Elmer Smurdley Excel Worksheet Functions 7 October 13th 07 04:01 PM
Determine file type David Sisson[_2_] Excel Programming 3 August 15th 06 09:13 AM
Type mismatch error problem when dealing with Strings David Goodall[_2_] Excel Programming 4 June 30th 05 01:40 PM
Help - Type mismatch when running loop with strings from arrays Marie J-son[_5_] Excel Programming 3 March 19th 05 08:36 PM


All times are GMT +1. The time now is 09:57 PM.

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"