#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default place code where?

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 143
Default place code where?

On Saturday, September 8, 2012 4:09:38 AM UTC-4, Stephen wrote:
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/Writin...ionsInVBA.aspx
for specifics on UDFs



I would avoid the Private
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,522
Default place code where?

On Saturday, September 8, 2012 3:09:38 AM UTC-5, Stephen wrote:
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
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 24
Default place code where?

On Saturday, September 8, 2012 6:09:38 PM UTC+10, Stephen wrote:
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
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
How to code, AND where to place it !! Corey Excel Programming 6 January 6th 07 12:50 PM
Where to place code that changes a cell value? George Furnell[_2_] Excel Programming 1 February 20th 06 07:47 AM
where do i place the code ? Asha Excel Programming 2 October 18th 05 04:13 PM
Wherre best to place code luke New Users to Excel 2 August 22nd 05 08:25 PM
Where to place Code question Stuart[_21_] Excel Programming 9 April 28th 05 08:06 PM


All times are GMT +1. The time now is 01:05 PM.

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

About Us

"It's about Microsoft Excel"