Fundet på nettet:OK, this isn't exactly simple.
It requires these steps:
- Open your file in Excel
- Open the visual basic editor from Excel (Alt-F11)
- in the project explorer window (open that window using the "View" menu if it isn't open already), locate your file and double click on it.
- Choose "Insert, Class module" from the menu
- Open the properties window (View, properties) and change the Name of the class (now reads "Class1") to clsTimer.
- IN the code window of clsTimer paste this code:
Option Explicit
Private msCellAddress As String
Private mdtEndTime As Date
Public Property Get CellAddress() As String
CellAddress = msCellAddress
End Property
Public Property Let CellAddress(ByVal sCellAddress As String)
msCellAddress = sCellAddress
End Property
Public Property Get EndTime() As Date
EndTime = mdtEndTime
End Property
Public Property Let EndTime(ByVal dtEndTime As Date)
mdtEndTime = dtEndTime
End Property
- Insert a module (Insert, module from the menu)
- paste in this code:
Option Explicit
Private mdNextTime As Double
Private mcolTimers As Collection
Public Function CountDown(EndTime As Date) As Variant
Dim cTimer As clsTimer
Dim sCellAddress As String
sCellAddress = Application.Caller.Address(external:=True)
Application.Volatile
If TypeName(Application.Caller) <> "Range" Then
Else
If IsIn(mcolTimers, sCellAddress) Then
Set cTimer = mcolTimers(sCellAddress)
mcolTimers.Remove sCellAddress
Else
Set cTimer = New clsTimer
With cTimer
.CellAddress = sCellAddress
.EndTime = EndTime
End With
End If
End If
With cTimer
.CellAddress = sCellAddress
.EndTime = EndTime
If .EndTime - (Now - Int(Now)) > 0 Then
CountDown = .EndTime - (Now - Int(Now))
Else
CountDown = 0
End If
End With
If mcolTimers Is Nothing Then
Set mcolTimers = New Collection
End If
mcolTimers.Add cTimer, sCellAddress
Set cTimer = Nothing
End Function
Private Function IsIn(colCollection As Collection, sName As String)
Dim cTimer As clsTimer
On Error Resume Next
Set cTimer = mcolTimers(sName)
IsIn = (Err.Number = 0)
Set cTimer = Nothing
End Function
Public Sub Auto_Open()
Application.OnTime Now, "UpdateTimers"
End Sub
Public Sub Auto_Close()
StopTimers
End Sub
Sub UpdateTimers()
mdNextTime = Now + TimeValue("00:00:01")
Application.OnTime mdNextTime, "UpdateTimers"
Application.Calculate
End Sub
Sub StopTimers()
Application.OnTime mdNextTime, "UpdateTimers", , False
End Sub
- Now in any cell, enter a formula like this:
=CountDown(Time(16,20,00))
and format the cell as time.
- Save your file, close it and open it again.
The cell should start to count down to 00:00 (which it reaches at whatever time you entered).
Virker godt nok ikke hos mig :-(
Men hvis jeg skriver formlen: =CountDown(TID(20;0;0))
så gør den ;-)
Håber du kan bruge det.