Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VB coding for formatting time used in calculations

I am a novice at VB coding so this is probably an
elementary question.

I would like to format a range in [h]:mm: format so that I
can use it in a calculation. Right now I can use the
spreadsheet format but in order to 'activate' the format I
have to doubleclick EACH cell and then move to another
cell. There are 200 lines of data that needs to be
formatted and 'activated' so I thought a VB routine would
be more efficient.

This is what I have come up with. I have no trouble with
formatting it, it's the coding for the 'doubliclick'that I
am having problem with. Coding example:

Sub DirectTimetoCalculateTimeFormat()
'
Columns("D:D").Select
Selection.NumberFormat = "[h]:mm:"
End Sub

Sub DoubleClicks()
Dim myRange As Range
Set myRange = Worksheets("Sheet1").Range("d8:e300")
For Each c In myrange.cells
Application.DoubleClick
Application.MoveAfterReturn = TRUE
Application.MoveAfterReturnDirection = xlDown
Next
End Sub

From what I have read the 'For Each..Next' loop is a good
statement to use or is there another way of coding this
altogether?

I would like to use the same procedure for different
spreadsheets so I have saved it in personal.xls. Do I have
to define the spreadsheet in the procedure or is it
assumed when I open the Macro (saved in personal.xls)in the
current spreadsheet?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default VB coding for formatting time used in calculations

Hi Tat,

Typically, when a value is not "recognized" until you double-click, that
means Excel has not evaluated the entry as a number yet. Times/dates are
stored as numbers in Excel. To force Excel to reevaluate the cells without
having to double-click each one, you can do this:

1) enter 0 in an empty cell
2) copy that cell
3) select the range to reevaluate
4) paste special paste=values and operation=add

That will, in effect, add 0 to each cell in the range, which will force
Excel to recognize the date/times. You could record a macro while doing
this if you need a programmatic solution.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Tat wrote:
I am a novice at VB coding so this is probably an
elementary question.

I would like to format a range in [h]:mm: format so that I
can use it in a calculation. Right now I can use the
spreadsheet format but in order to 'activate' the format I
have to doubleclick EACH cell and then move to another
cell. There are 200 lines of data that needs to be
formatted and 'activated' so I thought a VB routine would
be more efficient.

This is what I have come up with. I have no trouble with
formatting it, it's the coding for the 'doubliclick'that I
am having problem with. Coding example:

Sub DirectTimetoCalculateTimeFormat()
'
Columns("D:D").Select
Selection.NumberFormat = "[h]:mm:"
End Sub

Sub DoubleClicks()
Dim myRange As Range
Set myRange = Worksheets("Sheet1").Range("d8:e300")
For Each c In myrange.cells
Application.DoubleClick
Application.MoveAfterReturn = TRUE
Application.MoveAfterReturnDirection = xlDown
Next
End Sub

From what I have read the 'For Each..Next' loop is a good
statement to use or is there another way of coding this
altogether?

I would like to use the same procedure for different
spreadsheets so I have saved it in personal.xls. Do I have
to define the spreadsheet in the procedure or is it
assumed when I open the Macro (saved in personal.xls)in the
current spreadsheet?


  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default VB coding for formatting time used in calculations

Thank you, thankyou, thankyou! It works wonderfully!
-----Original Message-----
Hi Tat,

Typically, when a value is not "recognized" until you

double-click, that
means Excel has not evaluated the entry as a number yet.

Times/dates are
stored as numbers in Excel. To force Excel to reevaluate

the cells without
having to double-click each one, you can do this:

1) enter 0 in an empty cell
2) copy that cell
3) select the range to reevaluate
4) paste special paste=values and operation=add

That will, in effect, add 0 to each cell in the range,

which will force
Excel to recognize the date/times. You could record a

macro while doing
this if you need a programmatic solution.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address

unmonitored]


Tat wrote:
I am a novice at VB coding so this is probably an
elementary question.

I would like to format a range in [h]:mm: format so

that I
can use it in a calculation. Right now I can use the
spreadsheet format but in order to 'activate' the

format I
have to doubleclick EACH cell and then move to another
cell. There are 200 lines of data that needs to be
formatted and 'activated' so I thought a VB routine

would
be more efficient.

This is what I have come up with. I have no trouble with
formatting it, it's the coding for

the 'doubliclick'that I
am having problem with. Coding example:

Sub DirectTimetoCalculateTimeFormat()
'
Columns("D:D").Select
Selection.NumberFormat = "[h]:mm:"
End Sub

Sub DoubleClicks()
Dim myRange As Range
Set myRange = Worksheets("Sheet1").Range("d8:e300")
For Each c In myrange.cells
Application.DoubleClick
Application.MoveAfterReturn = TRUE
Application.MoveAfterReturnDirection = xlDown
Next
End Sub

From what I have read the 'For Each..Next' loop is a

good
statement to use or is there another way of coding this
altogether?

I would like to use the same procedure for different
spreadsheets so I have saved it in personal.xls. Do I

have
to define the spreadsheet in the procedure or is it
assumed when I open the Macro (saved in personal.xls)in

the
current spreadsheet?


.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Time calculations for Scheduled vs Actual Employee Time and Wages The Caterer Excel Discussion (Misc queries) 4 November 29th 09 11:51 PM
Time calculations for Scheduled Time vs. Actual Time Worked The Caterer Excel Discussion (Misc queries) 1 November 29th 09 08:08 AM
Time difference calculations, daylight savings time, Excel Tim Excel Discussion (Misc queries) 1 December 28th 06 04:18 PM
Conditional formatting: Colour coding Kelly Excel Discussion (Misc queries) 4 January 18th 06 11:11 AM
convert time imported as text to time format for calculations batfish Excel Worksheet Functions 3 October 27th 05 11:24 PM


All times are GMT +1. The time now is 11:32 PM.

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

About Us

"It's about Microsoft Excel"