Solved

VB Excel Object

Posted on 2002-05-29
3
143 Views
Last Modified: 2010-05-02
Hello,

I am writing an import routine to import data from an Excel spreadsheet into a SQL Server database.  The problem I am having is that one of the columns has a formatting on it and I can't retrieve the data as it appears.  Here is the info about this column:

Column name:         AS4TIME
Visual Appearance:   12:42:49
Fx (formula bar):    12:42:49 PM
Formatted as text:   0.529733796

My code is as follows:

pxlSheet.Cells(lngCurrentRecord, TIME_COL).Value
This returns:  0.529733796, which is unacceptable

so I tried:
pxlSheet.Cells(lngCurrentRecord, TIME_COL).Text
This returns: 12:42:49, which is what you see when you view the spreadsheet, but I need that 'PM' that appears in the formula bar.

I don't want to modify the sheet in any way.  Any help in retrieving 12:42:49 PM from this cell would be greatly appreciated
0
Comment
Question by:dentyne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Expert Comment

by:Crin
ID: 7042788
Hi,

use CDate(pxlSheet.Cells(lngCurrentRecord, TIME_COL).Value)

Sincerely,
Crin
0
 
LVL 2

Accepted Solution

by:
Crin earned 100 total points
ID: 7042794
Sorry, forgot AM-PM issue:

Format(CDate(pxlSheet.Cells(lngCurrentRecord, TIME_COL).Value), "hh:mm:ss AMPM")

SIncerely,
Crin
0
 
LVL 1

Author Comment

by:dentyne
ID: 7042826
Hey that's great; thanks for the help!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question