LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Converting to macro

If the text is in its own cell or cells, it can be avoided by
testing for a numeric value in the cell and ignoring any cells that
aren't numeric. If it's mixed in the same cell as the times you want
to convert, it's a bit trickier.

By adding an optional range argument, the macro will work with
either the Selection or the specified range:

Public Sub ConvertDecimalTimesToTimes(Optional rng As Range)
Dim cell As Range
If rng Is Nothing Then Set rng = Selection
For Each cell In rng
With cell
If Not IsEmpty(.Value) Then
If IsNumeric(.Value) Then
.Value = TimeSerial(Int(.Value), _
(.Value - Int(.Value)) * 100, 0)
.NumberFormat = "[h]:mm"
End If
End If
End With
Next cell
End Sub

Note that adding an optional argument means that the macro will no
longer show up in the Macro list when you select Tools/Macro/Macros,
but you can still type in the name (you may want to make it a bit
shorter, in that case).


In article ,
(angelo325) wrote:

1. Some of the data contained words or letters so I got a Type
MisMatch error 13. Can this be catered for? A quick search on Google
showed this was a common problem but I have played around with your
code for so long I just haven't got the will to sort it out tonight.
Give me an engine block any day!

2. I wanted to call this Macro after completion of another in which a
column of data is copied from another workbook into different named
sheets. Because my knowledge of VB is zero how can I set the range
just copied in preparation for ConvertDecimalTimesToTimes and then
move onto the next?

 
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
macro for converting excel to adobe pdf matt Excel Discussion (Misc queries) 1 February 22nd 07 06:53 PM
Converting Macro to Perl - charting help dravon Charts and Charting in Excel 0 May 6th 06 12:02 AM
converting Lotus 123 macro to Excell macro mark h Excel Discussion (Misc queries) 6 July 11th 05 01:28 PM
macro for converting text file to excel Tom Ogilvy Excel Programming 0 September 5th 03 12:49 PM
macro for converting text file to excel tomhaddock[_3_] Excel Programming 0 September 5th 03 11:40 AM


All times are GMT +1. The time now is 05:41 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"