[ABC home]    [ABC Archives by Issue]   [ABC Archives by Author]  [Search]  [Privacy]

 

ABC logo
ABC Home

 

Advertise in ABC

Learn more
about
Chad Welch
Chad Welch

Read
Chad's Archives
Read Chad's Archives

Online classes
at Eclectic Academy
 Instructor led online courses at Eclectic Academy

PowerPoint to Exe
convert PowerPoint presentations to exes

Lock 'n Hide
Folder Security

Hide files and folders in Windows 9X

 

ABC ~ All 'Bout Computers
The Online Web-azine for Computer Enthusiasts
-- brought to you by
Visit Linda's Computer Stop

contents page for this issue

Chad's Macro Mania
~~Chad K. Welch

DATES IN VBA

Last issue we discussed the way Microsoft Office software handles dates.  However, VBA handles dates a little bit differently.  Well, I take that back.  The dates and times are handled the same way, but representing them may be a little different sometimes.  For example, suppose you wanted to keep track of the finish times in your local “Tortoise and Hare Marathon Run.”  In Excel you would set the cell format to keep track of total hours and minutes (custom format [H]:mm). 
 
In VBA the format doesn’t work.  In other words, if you have a textbox and try to run the following code, you’d expect to see 30:43 since that is 1.28 days: 

TextBox1.Text = Format(1.28, "[H]:mm"). 

However, :12 shows up in the textbox.  Where did that come from? 

There are a couple of ways to “smudge” the answer and display what you really think should be in there.  I use a formula similar to:

TextBox1.Text = Int(1.28 * 24) & ":" & Format(1.28 * 1440 - Int(1.28 * 24) * 60, "00")

Like I say, this is just one of many ways.  I’d be interested to see how you’ve handled similar problems.  Please email them to me.


Remember, $5.00 to anyone who sends me a question or idea that I can use in this article.

Chad K. Welch works as a technician/enabler in Utah.  He is available for consulting or application programming with Microsoft Office and VBA.  Do you have a question or tip you’d like to have Chad address in this column?  Send an email to linda@personal-computer-tutor.com or contact him directly at chad@welchkins.com for more information.

My Newest Book
Excel 2003 Study Guide

published by Wiley
get it at Amazon,
at Barnes & Noble,
or at Borders

 


 Support ABC

Linda's Ebooks
Ebooks on Access, Excel, Outlook, PowerPoint, Publisher, and Word

Linda's CD
Order Linda's CD and learn all of the Office programs

The Newbie Club
Learn all about computers the easy way

Online classes
at Eclectic Academy
 Instructor led online courses at Eclectic Academy

FrontLook
Add-ins
& Screen Capture


 

 

Privacy Policy, Disclaimer, and Legal Stuff

Pay Per Click Ads by Pay Per Click Advertising by Kontera

This page was last updated on Tuesday, September 23, 2008 . copyright © 2000 - 2008, Linda F. Johnson, Linda's Computer Stop, ABC ~ All 'Bout Computers. All rights reserved.