Application.ScreenUpdating = False
Sheets("Foglio2").Select
Cells.Select
selection.ClearContents
Range("A1").Select
Sheets("Foglio1").Select
Cells.Select
Selection.Copy
Sheets("Foglio2").Select
Cells.Select
ActiveSheet.Paste
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range("A65536").Select
Selection.End(xlUp).Select
riga_fi = ActiveCell.Row
riga_in = 2
col_in = 3
intervallo = "C" & riga_in & "." & "L" & riga_fi
Range(intervallo).Select
Selection.ClearContents
I = col_in
k = 0
For j = riga_in To riga_fi
If Cells(j, 1) = Cells(j + 1, 1) Then
If k > 0 Then
Cells(k, I) = Cells(j, 2)
Else
Cells(j, I) = Cells(j, 2)
k = j
End If
I = I + 1
Else
If Cells(j - 1, 1) = Cells(j, 1) Then
If k > 0 Then
Cells(k, I) = Cells(j, 2)
k = 0
End If
I = col_in
End If
End If
Next j
If Range("a1").Value = Range("a2").Value And Range("a1").Value <> Range("a3").Value Then
Range("c1").Value = Range("b1").Value
Range("d1").Value = Range("b2").Value
End If
If Range("a1").Value = Range("a2").Value And Range("a1").Value >= Range("a3").Value Then
Range("C2:AZ2").Select
Selection.Cut
Range("D1").Select
ActiveSheet.Paste
Range("C1").Value = Range("B1").Value
End If
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("A1").Select
ActiveCell.FormulaR1C1 = 0
x = Application.WorksheetFunction.CountA(Range("a2:a60000")) + 1
For I = 2 To x
If Range("a" & I).Value <> Range("a" & I + 1).Value And Range("a" & I).Value <> Range("a" & I - 1).Value Then
Range("c" & I).Value = Range("b" & I).Value
End If
Next I
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
CONTA = Application.WorksheetFunction.CountA(Range("a1:a60000"))
For I = 1 To CONTA
Range("B" & I).Select
If Range("B" & I).Value = "" And Range("A" & I).Value <> "" Then
Range("B" & I).EntireRow.Delete
I = I - 1
End If
Next I
Application.ScreenUpdating = True |