place code where?

S

Stephen

Hello, can someone explain how and where does this code go to get it to work?
Does it go in general macro or do I need to put in a module.

Private Function SecondsToTime(byval dSeconds as Double) _
as String
SecondsToTime = Format(DateAdd("s", dSeconds, "00:00:00"), "HH:mm:ss")
End Function


regards
Stephen
 
J

James Ravenswood

Hello, can someone explain how and where does this code go to get it to work?

Does it go in general macro or do I need to put in a module.



Private Function SecondsToTime(byval dSeconds as Double) _

as String

SecondsToTime = Format(DateAdd("s", dSeconds, "00:00:00"), "HH:mm:ss")

End Function





regards

Stephen

It works just fine in a standard module:


User Defined Functions (UDFs) are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it.

To remove the UDF:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To use the UDF from Excel:

=myfunction(A1)

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

or

http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx
for specifics on UDFs



I would avoid the Private
 
D

Don Guillett

Hello, can someone explain how and where does this code go to get it to work?

Does it go in general macro or do I need to put in a module.



Private Function SecondsToTime(byval dSeconds as Double) _

as String

SecondsToTime = Format(DateAdd("s", dSeconds, "00:00:00"), "HH:mm:ss")

End Function





regards

Stephen

Assuming your function is OK it needs to go into a REGULAR module. Not a sheet module
 
S

stephen.ditchfield

Hello, can someone explain how and where does this code go to get it to work?

Does it go in general macro or do I need to put in a module.



Private Function SecondsToTime(byval dSeconds as Double) _

as String

SecondsToTime = Format(DateAdd("s", dSeconds, "00:00:00"), "HH:mm:ss")

End Function





regards

Stephen
Thank You
James & Don
this fixes a problem for me
much appreciated
regards
Stephen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

tracking time 4
Time remaining until event 2
Can't Stop the clock 2
automation error 0
Time with decimal places? 4
Time with VBA code 8
Formatting short times 2
Byte code interpretation by hand 5

Top