Solved

VB Excel Object

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now