View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jamie Collins Jamie Collins is offline
external usenet poster
 
Posts: 593
Default Cell formatting when pulling into VB

Skeletonhat wrote ...

I have an excel spreadsheet that im pulling into a VB flexgrid with
ADODB.

But i have a collumn that has a header and sub header and then below
that is several records of times.
When it pulls from that table, it formats EVERYTHING in that collumn as
a time thus nullifying the header and sub header.

I tried adding 'imex=1' to the extrended proporties but then "2:00 PM"
becomes .58333333...


Sounds like you are binding the flexgrid to an ADODB recordset (I
don't usually bother because, unlike the DataGrid, the flexgrid
doesn't support strict data typing, editing, etc) or adding the data
in one hit e.g.

MSFlexGrid1.Clip = rs.GetString(adClipString):

If you add the data to the flexgrid yourself e.g. by looping through
the recordset, you have control over the format of the text.

It also sounds like you consider the heading and subheading to be data
items in their own right (headings are usually metadata rather than
data), presumably of 'text' data type. You will always have a
fundamental problem mixing data types and you've seen both of Jet's
solutions: 1) cast the values as text (which affects the formatting of
your times) and 2) null the values that don't fit the majority type
(which knocks out your headings).

Assuming you have some idea of the approximate cell address of your
heading, you can use them in the table name. For example, say you are
currently using HDR=NO in the connection and you SQL is:

SELECT F1 FROM [Sheet1$];

If you know your headers in cells A1 and A2, then keep the HDR=NO and
select the headers (text) using:

SELECT F1 AS MyHeadings FROM [Sheet1$A1:A2];

and similarly select the data (times) using:

SELECT F1 AS MyTimes FROM [Sheet1$A3:A65535];

(note: will not fetch all the rows on the sheet, rather just those in
the UsedRange).

If you know your headers are in rows 1 and two and are in the leftmost
column (i.e. F1) but you are not exactly sure if the table starts in
column A or not, then be a bit more vague with the cell addresses e.g.
for headers:

SELECT F1 AS MyHeadings FROM [Sheet1$1:2];

for the data:

SELECT F1 AS MyTimes FROM [Sheet1$3:65535];

Jamie.

--