Sub rigaDiOre()
'
' rigaDiOre Macro
' tratta una giornata secondo una regola
'
'prima parte da mettere in constant
Dim e1 As String, e2 As String, e3 As String, e4 As String 'colonne entrate
Dim u1 As String, u2 As String, u3 As String, u4 As String 'colonne uscite
Dim uu As String, uus As String ' ultima uscita e scrematura
Dim colReg As Range, cReg As String, rReg As String
Dim rOre As String, regola As String
Dim rIM, rFS
Dim rPD, rPS, rPQ, PQ, effe, difp, difn
Dim rT, rPr
'CARICA DATI DA RIGA DI ORE
rOre = ActiveCell.Row ' andrà tolto passandolo in parametro
regola = Cells(rOre, 12).Value
ass = Cells(rOre, 18).Value
e1 = Cells(rOre, 3).Value
u1 = Cells(rOre, 4).Value
e2 = Cells(rOre, 5).Value
u2 = Cells(rOre, 6).Value
e3 = Cells(rOre, 7).Value
u3 = Cells(rOre, 8).Value
e4 = Cells(rOre, 9).Value
u4 = Cells(rOre, 10).Value
'inserire qui un controllo sul numero di valori presenti nelle variabili "e" e "u" sopra
'se dispari, Cells(rOre, 17).Value = "ERRORE" e poi exit sub
'---------continuo controllando manualmente di eseguire solo su righe perfette
'--------parte da sostituire con TrovaColonna
With Sheets("monitor").UsedRange
Set colReg = .Find(regola, LookIn:=xlValues)
If Not colReg Is Nothing Then
cReg = colReg.Column
rReg = colReg.Row
Else
cReg = "Non Trovato"
End If
End With
'MsgBox ("la regola sta in: " & cReg & "," & rReg)
'--------fine parte da sostituire con TrovaColonna
'CARICA CARATTERISTICHE REGOLA
rIM = Sheets("monitor").Cells(rReg, cReg + 1).Value 'inizio mattina
rFS = Sheets("monitor").Cells(rReg, cReg + 2).Value 'fine sera
rPD = Sheets("monitor").Cells(rReg, cReg + 3).Value 'pausa dopo quanto
rPS = Sheets("monitor").Cells(rReg, cReg + 4).Value 'pausa se ore > x
rPQ = Sheets("monitor").Cells(rReg, cReg + 5).Value 'pausa imposta, quanti minuti
rT = Sheets("monitor").Cells(rReg, cReg + 6).Value 'orario teorico
rPr = Sheets("monitor").Cells(rReg, cReg + 7).Value 'eventuale premio
'CALCOLA
If e1 < rIM Then e1 = rIM
uu = Max(u1, u2, u3, u4) ' <== QUI CASCA L'ASINO !!!
If uu > rFS Then
uus = uu - rFS 'scrematura ultima uscita se oltre rIM
Else
uus = 0
End If
p1 = u1 - e1 'sono i periodi di lavoro della giornata: uscita meno entrata
If Not e2 = "" Then
p2 = u2 - e2
Else
p2 = 0
End If
If Not e3 = "" Then
p3 = u3 - e3
Else
p3 = 0
End If
If Not e4 = "" Then
p4 = u4 - e4
Else
p4 = 0
End If
If u1 > rPD And p1 > rPS Then
p1 = p1 - rPQ
Else
rPQ = "ok"
End If
effe = p1 + p2 + p3 + p4 - uus
If effe > rT Then
difp = effe - rT
Else
difn = rT - effe 'bisogna far precedere il segno "-"
End If
'MsgBox (rPQ & " " & effe & " " & rT)
'SCRIVE
Cells(rOre, 15) = rPQ
Cells(rOre, 16) = rT
Cells(rOre, 17) = effe
Cells(rOre, 20) = difp
Cells(rOre, 21) = difn
End Sub |