
Sub Prova1() Dim secondi, secondi1, TOT As Double Dim x, y, z As TextBox secondi = 0 secondi1 = 0 UserForm1.Show vbModeless secondi = CDbl(UserForm1.TextBox1.Text) * 3600 + CDbl(UserForm1.TextBox2.Text) * 60 + CDbl(UserForm1.TextBox3.Text) secondi1 = CDbl(Hour(Now)) * 3600 + CDbl(Minute(Now)) * 60 + CDbl(Second(Now)) If secondi < secondi1 Then TOT = 86399 - secondi1 + secondi Else TOT = secondi - secondi1 End If h = TOT 3600 m = CInt((TOT Mod 3600) 60) s = CInt((TOT Mod 3600) Mod 60) 'al posto delle tre istruzioni precedenti si poteva usare l'istruzione Format.... If h = 0 And m = 0 And s = 0 Then MsgBox "PROVA, SE SEI GIUNTO FINO QUI IL CODICE FA TUTTO QUELLO CHEW HAI IMPOSTATO)" End If End Sub |
Sub Avvia()
Foglio1.Select
[M1] = [B2] / 86400 + Time
Conto_alla_Rovescia
End Sub
Sub Conto_alla_Rovescia()
If ThisWorkbook.Worksheets("Foglio1").Range("M1").Value <= Time Then
MsgBox "Tempo SCADUTO ! ! !"
Exit Sub
End If
ThisWorkbook.Worksheets("Foglio1").Range("A1").Value = Format(ThisWorkbook.Worksheets("Foglio1").Range("M1").Value - Time, "hh:mm:ss")
DoEvents
Application.OnTime Now + TimeSerial(0, 0, 1), "Conto_alla_Rovescia"
End Sub
|
Sub Avvia()
response = InputBox("Inserisci il tempo per la prova in secondi." & chr13 & chr13 & chr13 & " Ad esempio se vuoi inserire come tempo 1 ora " _
& chr13 & " devi inserire 3600")
Foglio1.Select
[b2] = response
[m1] = [b2] / 86400 + Time
UserForm1.Label1 = "Il tempo a tua disposizione è:" & ThisWorkbook.Worksheets("Foglio1").Range("A1").Value
'Application.OnTime Now + TimeSerial(0, 0, 1), "Conto_alla_Rovescia"
Conto_alla_Rovescia
End Sub
Sub Conto_alla_Rovescia()
If ThisWorkbook.Worksheets("Foglio1").Range("M1").Value <= Time Then
MsgBox "Tempo SCADUTO ! ! !"
Exit Sub
End If
ThisWorkbook.Worksheets("Foglio1").Range("A1").Value = Format(ThisWorkbook.Worksheets("Foglio1").Range("M1").Value - Time, "hh:mm:ss")
DoEvents
Application.OnTime Now + TimeSerial(0, 0, 1), "Conto_alla_Rovescia"
End Sub
|
Option Explicit
Sub Avvia()
Dim response
response = InputBox("Inserisci il tempo per la prova in secondi." & vbCrLf & " Ad esempio se vuoi inserire come tempo 1 ora " _
& " devi inserire 3600")
Foglio1.Select
[b2] = response
[M1] = [b2] / 86400 + Time
UserForm1.Label1 = "Il tempo a tua disposizione è: " & [A1]
UserForm1.Show vbModeless
Call Conto_alla_Rovescia
End Sub
Sub Conto_alla_Rovescia()
If [M1] <= Time Then
MsgBox "Tempo SCADUTO ! ! !"
Unload UserForm1
Exit Sub
End If
[A1] = Format([M1] - Time, "hh:mm:ss")
'aggiorna l'userform
UserForm1.Label1 = "Il tempo a tua disposizione è: " & Format([M1] - Time, "hh:mm:ss")
DoEvents
Application.OnTime Now + TimeSerial(0, 0, 1), "Conto_alla_Rovescia"
End Sub |
Sub Mischia() 'mischia tutte le righe del foglio
'richiede come parametro la stringa del nome del foglio
Dim i As Long, riga As Long, ultima As Long, rr As Long, temp As Long, Sh As Worksheet
Set Sh = ThisWorkbook.Sheets(1)
With Sh
ultima = Range("A1").End(xlDown).Row 'Ultima riga occupata del foglio
temp = ultima + 1 'riga di "appoggio" che uso per mischiare
For riga = 2 To ultima - 1 'dalla prima alla penultima riga
Do
rr = Int((ultima * Rnd) + 1) 'scelgo una riga a caso
Loop Until rr > riga 'se è una riga gia mischiata ripeto il passo precedente
Cells(riga, 1).EntireRow.Copy Destination:=Cells(temp, 1) 'copio la riga da mischiare nella riga di appoggio
Cells(rr, 1).EntireRow.Copy Destination:=Cells(riga, 1) 'copio la riga scelta a caso sulla riga da mischiare
Cells(temp, 1).EntireRow.Copy Destination:=Cells(rr, 1) 'copio la riga di appoggio sulla riga scelta a caso
Next riga 'passa alla successiva riga da mischiare
Cells(temp, 1).EntireRow.ClearContents 'cancello la riga di appoggio
End With 'Sh
Set Sh = Nothing
End Sub |
'aggiorna l'userform
UserForm1.Label1 = "Il tempo a tua disposizione è: " & Format([M1] - Time, "hh:mm:ss")
|
Sub Avvia()
Dim response
response = InputBox("Inserisci il tempo per la prova in secondi." & vbCrLf & "Ad esempio se vuoi inserire come tempo 1 ora " _
& " devi inserire 3600.")
If response = "" Then
UserForm1.OptionButton1.Visible = False
UserForm1.OptionButton2.Visible = False
UserForm1.OptionButton3.Visible = True
UserForm1.OptionButton3 = False
UserForm1.Label9.Visible = False
Exit Sub
End If
Worksheets("Foglio3").Select
[b2] = response
[M1] = [b2] / 86400 + Time
UserForm1.Label9 = "Il tempo a tua disposizione è: " & [A1]
'UserForm1.Show vbModeless
Call Conto_alla_Rovescia
End Sub
Sub Conto_alla_Rovescia()
'bln = True
If [M1] <= Time Then
MsgBox "Tempo SCADUTO ! ! !"
Unload UserForm1
Exit Sub
End If
[A1] = Format([M1] - Time, "hh:mm:ss")
'aggiorna l'userform
UserForm1.Label9 = "Il tempo a tua disposizione è: " & Format([M1] - Time, "hh:mm:ss")
DoEvents
Application.OnTime Now + TimeSerial(0, 0, 1), "Conto_alla_Rovescia"
End Sub |
