PC Review


Reply
Thread Tools Rate Thread

Determine format type from strings

 
 
=?Utf-8?B?QUxW?=
Guest
Posts: n/a
 
      30th Jan 2007
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 With Quote
 
 
 
 
=?Utf-8?B?Z2VyZG1haW4=?=
Guest
Posts: n/a
 
      31st Jan 2007
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.
>

 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      31st Jan 2007
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" <(E-Mail Removed)> wrote in message
news:092D4B30-3922-449D-ACF6-(E-Mail Removed)...
> 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 With Quote
 
=?Utf-8?B?QUxW?=
Guest
Posts: n/a
 
      31st Jan 2007
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" <(E-Mail Removed)> wrote in message
> news:092D4B30-3922-449D-ACF6-(E-Mail Removed)...
> > 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
using a row filled with strings to determine cell value NebJoel Microsoft Excel Misc 5 7th Feb 2009 04:35 AM
Fast way to determine if a string contains a member of a list of strings Karch Microsoft C# .NET 38 14th Mar 2008 12:29 AM
Fast way to determine if a string contains a member of a list of strings Karch Microsoft Dot NET 15 6th Mar 2008 10:07 PM
How to efficiently determine if a string contains any one of many strings Microsoft C# .NET 9 25th Jun 2007 06:28 PM
Dynamiclly Determine Type of Parameter and Type Cast it (code insi =?Utf-8?B?TGVubg==?= Microsoft C# .NET 1 14th Dec 2005 09:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:47 PM.