forumla to set varable without wirting to sheet

dantheman9

Board Regular
Joined
Feb 5, 2011
Messages
175
Is is possible to do a formula off the sheet and also set the varable numberformat?

example of what im trying to do;

Code:
Dim stime as String
Dim Refresh as Integer
 
 
stime = Formula(Refresh "/ 86400").NumberFormat = "hh:mm:ss"
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
right so I guess this needs to be a function?
so how can i get this to work?

Code:
Sub test
Dim stime as String
Dim Refresh as Integer
 
 
stime = ctime(refresh)
 
End Sub
 
Function ctime(number)
ctime = number / 86400
with ctime
.FormatNumber = "hh:mm:ss"
End With 
End Function
 
Upvote 0
ok so I have part of the function working, but the answer from the function seems to not be send back to the sub;

Code:
Sub test()
Dim refresh As Integer
Dim stime As Integer

refresh = 20 * 2       'cellhtml
stime = ctime(refresh)    ' stime is not updated with the value from ctime?
   
End Sub
 
 
Function ctime(number)
ctime = number / 86400
 
End Function

also can the ctime be converted into a time format? (effectly im looking to convert the value of refresh from seconds to hh:mm:ss.
 
Upvote 0
Hi there,

I'm not experienced at extremely small/large numbers and conversion/coercement needs, but off the top, yo uare declaring stime as an Integer. 40/86400 is way less than 1, hence the seeming non-return.
Rich (BB code):
Option Explicit
    
Sub test()
Dim refresh As Long
Dim stime As Variant
    
    refresh = 20 * 2       'cellhtml
    stime = ctime(refresh)    ' stime is not updated with the value from ctime?
End Sub
     
Function ctime(number) As Variant
    ctime = CDec(number / 86400)
    Debug.Print ctime
End Function
 
Upvote 0
thanks GTO that worked great - seems I need to brush up on how to set varables correctly! ....not to mention how to set them in functions too!
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,280
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top