A Microsoft Excel forum. ExcelBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » ExcelBanter forum » Excel Newsgroups » Excel Discussion (Misc queries)
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Time format set from VBA



 
 
Thread Tools Display Modes
  #1  
Old March 16th 06, 03:37 PM posted to microsoft.public.excel.misc
external usenet poster
 
Posts: n/a
Default Time format set from VBA

How do I go about setting the format of a cell to HH:MM from VBA?

I don't want the seconds showing. Just the Hour and Minutes. I have a
program that is collecting data and I need to fill one of the fields with the
time the data was taken. The worksheet is not setup ahead to pre-define the
cell formats. I need to format the cell as I'm putting the time into it.

Thanks for any help.
Mike

Ads
  #2  
Old March 16th 06, 04:35 PM posted to microsoft.public.excel.misc
external usenet poster
 
Posts: n/a
Default Time format set from VBA

Mike

Range("BlahBlah").NumberFormat = "hh:mm"

Cells(lRow,ICol)NumberFormat = "hh:mm"

HTH,
Bernie
MS Excel MVP


"Mike" > wrote in message
...
> How do I go about setting the format of a cell to HH:MM from VBA?
>
> I don't want the seconds showing. Just the Hour and Minutes. I have a
> program that is collecting data and I need to fill one of the fields with the
> time the data was taken. The worksheet is not setup ahead to pre-define the
> cell formats. I need to format the cell as I'm putting the time into it.
>
> Thanks for any help.
> Mike
>



  #3  
Old March 16th 06, 04:50 PM posted to microsoft.public.excel.misc
external usenet poster
 
Posts: n/a
Default Time format set from VBA

Thanks. I had checked in several places looking for just what you supplied
with no luck.

Mike

"Bernie Deitrick" wrote:

> Mike
>
> Range("BlahBlah").NumberFormat = "hh:mm"
>
> Cells(lRow,ICol)NumberFormat = "hh:mm"
>
> HTH,
> Bernie
> MS Excel MVP
>
>
> "Mike" > wrote in message
> ...
> > How do I go about setting the format of a cell to HH:MM from VBA?
> >
> > I don't want the seconds showing. Just the Hour and Minutes. I have a
> > program that is collecting data and I need to fill one of the fields with the
> > time the data was taken. The worksheet is not setup ahead to pre-define the
> > cell formats. I need to format the cell as I'm putting the time into it.
> >
> > Thanks for any help.
> > Mike
> >

>
>
>

  #4  
Old March 16th 06, 04:56 PM posted to microsoft.public.excel.misc
external usenet poster
 
Posts: n/a
Default Time format set from VBA

Mike,

The macro recorder is your friend. It would give you this when you format a cell for time, hours
and minutes:

Selection.NumberFormat = "h:mm;@"

which could be changed to

Selection.NumberFormat = "h:mm"
or
Selection.NumberFormat = "hh:mm"

and then you just usually need to change the Selection to a range object that you can use with your
code so that you don't select anything.

HTH,
Bernie
MS Excel MVP


> Thanks. I had checked in several places looking for just what you supplied
> with no luck.
>
> Mike



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting Text to Time format of XX:XX Marck Excel Discussion (Misc queries) 3 February 25th 06 04:48 PM
Adding Time Format jtinne Excel Discussion (Misc queries) 0 November 2nd 05 12:05 AM
Adding Time Format Sloth Excel Discussion (Misc queries) 0 November 1st 05 11:46 PM
Converting from time format to decimal and figuring the difference Steve Williams Excel Discussion (Misc queries) 1 July 30th 05 10:10 PM
Adding time damezumari Excel Discussion (Misc queries) 2 June 20th 05 08:35 PM


All times are GMT +1. The time now is 09:42 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 2004-2014 ExcelBanter.
The comments are property of their posters.