Option Explicit
Sub compila()
Dim F1 As Worksheet, F2 As Worksheet, F3 As Worksheet
Dim Area As Range, Cella As Object
Dim Uriga As Long, R As Long, C As Long, Cliente As Long, RR As Long
Dim Prodotto As String
RR = 2
Set F1 = Sheets("Ordini")
Set F2 = Sheets("Situazione")
Set F3 = Sheets("Produzione")
Set Area = F2.Range("C4:O13")
Uriga = F3.Range("A" & Rows.Count).End(xlUp).Row
If Uriga > 1 Then
F3.Range("A2:O" & Uriga).ClearContents
End If
For Each Cella In Area
If Cella.Interior.ColorIndex = 3 Then
R = Cella.Row
C = Cella.Column
Cliente = F2.Cells(2, C)
Prodotto = F2.Cells(R, 2)
F3.Cells(RR, 1) = Prodotto
F3.Cells(RR, 2) = F1.Cells(Cliente, 2)
F3.Cells(RR, 3) = F1.Cells(Cliente, 3)
F3.Cells(RR, 4) = F1.Cells(Cliente, 5)
RR = RR + 1
End If
Next
If RR > 2 Then
F3.Sort.SortFields.Clear
F3.Sort.SortFields.Add Key:=Range( _
"B2:B" & RR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With F3.Sort
.SetRange Range("A2:O" & RR)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End If
Set F1 = Nothing
Set F2 = Nothing
Set F3 = Nothing
Set Area = Nothing
End Sub |