ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Time format set from VBA (https://www.excelbanter.com/excel-discussion-misc-queries/77719-time-format-set-vba.html)

Mike

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


Bernie Deitrick

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




Mike

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





Bernie Deitrick

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





All times are GMT +1. The time now is 04:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com