
Option Explicit
Sub riporta_orari_parziali_per_mese()
Dim ur As Integer, rng_ID_1 As Range, rng_ID_2 As Range
Dim cell_id_1 As Range, cell_id_2 As Range
Dim cell_job_1 As Range, cell_job_2 As Range
Dim first_address As String
Dim job As Range
Dim month_job As Integer
Dim bFound As Boolean
'Foglio1.[C3:N2000].clearcontents : Foglio1.[P:P].Delete
Foglio1.Activate
With Foglio1
ur = .Cells(Rows.Count, 1).End(xlUp).Row
Set rng_ID_1 = .Range("A3:A" & ur)
End With
With Foglio2
ur = .Cells(Rows.Count, 1).End(xlUp).Row
Set rng_ID_2 = .Range("A2:A" & ur)
End With
For Each cell_id_1 In rng_ID_1
If cell_id_1 <> "" Then
Set cell_id_2 = rng_ID_2.Find(what:=cell_id_1, lookat:=xlWhole)
If Not (cell_id_2 Is Nothing) Then
first_address = cell_id_2.Address
Do
Set cell_job_2 = cell_id_2.Offset(, 1)
bFound = False
For Each cell_job_1 In Range(cell_id_1.Offset(, 1), cell_id_1.Offset(5, 1))
If cell_job_1 = cell_job_2 Then
month_job = Month(cell_job_2.Offset(, 1))
cell_job_1.Offset(, month_job) = cell_job_1.Offset(, month_job) + cell_job_2.Offset(, 4)
bFound = True
Exit For
End If
Next cell_job_1
If Not bFound Then
cell_id_1.Offset(, 15) = "JOB " & cell_job_2 & " Not found" 'rosso, JOB non trovato
cell_id_1.Offset(, 15).Interior.ColorIndex = 3
End If
If cell_id_1 = 1747 Then Debug.Print cell_id_2.Address ''''
Set cell_id_2 = rng_ID_2.FindNext(cell_id_2)
Loop While Not cell_id_2 Is Nothing And cell_id_2.Address <> first_address
Else
cell_id_1.Offset(1, 15) = "ID " & cell_id_1 & " Not found" 'rosso, ID non trovato
cell_id_1.Offset(1, 15).Interior.ColorIndex = 3
End If
End If
Next
MsgBox "Finito"
End Sub
|
Option Explicit
Sub riporta_orari_parziali_per_mese()
Dim ur As Integer, rng_ID_1 As Range, rng_ID_2 As Range
Dim cell_id_1 As Range, cell_id_2 As Range
Dim cell_job_1 As Range, cell_job_2 As Range
Dim first_address As String
Dim job As Range
Dim month_job As Integer
Dim bFound As Boolean
'Foglio1.[C3:N2000].clearcontents : Foglio1.[P:P].Delete
Foglio1.Activate
With Foglio1
ur = .Cells(Rows.Count, 1).End(xlUp).Row
Set rng_ID_1 = .Range("A1:A" & ur)
End With
With Foglio2
ur = .Cells(Rows.Count, 1).End(xlUp).Row
Set rng_ID_2 = .Range("A2:A" & ur)
End With
For Each cell_id_1 In rng_ID_1
If cell_id_1 <> "" And Val(cell_id_1) <> 0 Then
Set cell_id_2 = rng_ID_2.Find(what:=cell_id_1, lookat:=xlWhole)
If Not (cell_id_2 Is Nothing) Then
first_address = cell_id_2.Address
Do
Set cell_job_2 = cell_id_2.Offset(, 4)
bFound = False
For Each cell_job_1 In Range(cell_id_1.Offset(, 2), cell_id_1.Offset(5, 2))
If cell_job_1 = cell_job_2 Then
month_job = Month(cell_job_2.Offset(, 4))
cell_job_1.Offset(, month_job) = cell_job_1.Offset(, month_job) + cell_job_2.Offset(, 7)
bFound = True
Exit For
End If
Next cell_job_1
If Not bFound Then
cell_id_1.Offset(, 16) = "JOB " & cell_job_2 & " Not found" 'rosso, JOB non trovato
cell_id_1.Offset(, 16).Interior.ColorIndex = 3
End If
Set cell_id_2 = rng_ID_2.FindNext(cell_id_2)
Loop While Not cell_id_2 Is Nothing And cell_id_2.Address <> first_address
Else
cell_id_1.Offset(1, 16) = "ID " & cell_id_1 & " Not found" 'rosso, ID non trovato
cell_id_1.Offset(1, 16).Interior.ColorIndex = 3
End If
End If
Next
MsgBox "Finito"
End Sub
|
