Solved

VB Excel Object

Posted on 2002-05-29
3
142 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
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

726 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