Sub Salva_Pulizia2()
Application.ScreenUpdating = False
Dim Ricerca1 As Range, Ricerca2 As Range, DData As Date
Dim Dove1, Dove2, R1, R2, Nomi1, Nomi2, Nome, y, x, riga
Sheets("DATI").Select
Set Ricerca1 = Sheets("PULIZIA").Range("H1:IP1")
Set Ricerca2 = Sheets("PULIZIA").Range("H69:IP69")
Set Nomi1 = Sheets("PULIZIA").Range("A4:A19")
Set Nomi2 = Sheets("PULIZIA").Range("A72:A87")
riga = Range("Z" & Rows.Count).End(xlUp).Row
For y = 29 To 56
DData = Cells(1, y).Value' esempio 22/2/2013
For x = 2 To riga
If Cells(x, y) <> "" Then
Nome = ""
Nome = Cells(x, 26)
Dove1 = 0
Dove2 = 0
R1 = 0
R2 = 0
On Error Resume Next
Dove1 = Ricerca1.Find(DData, LookIn:=xlValues, LookAt:=xlWhole).Column
Dove2 = Ricerca2.Find(DData, LookIn:=xlValues, LookAt:=xlWhole).Column
If Dove1 <> 0 Then
R1 = Nomi1.Find(LookIn:=xlValues, LookAt:=xlWhole).Row
Sheets("PULIZIA").Cells(R1, Dove1) = Sheets("Dati").Cells(x, y)
End If
If Dove2 <> 0 Then
R2 = Nomi2.Find(Nome, LookIn:=xlValues, LookAt:=xlWhole).Row
Sheets("PULIZIA").Cells(R2, Dove2) = Sheets("Dati").Cells(x, y)
End If
End If
Next x
Next y
MsgBox "Inserimento effettuato"
Application.ScreenUpdating = True
End Sub |