
Sub Macro1()
Dim rng As Range
Dim cel As Range
Dim ur As Long
Dim lr As Long
Dim FGL As String
Set rng = Range("a1:a" & Cells(Rows.Count, 1).End(xlUp).Row)
For Each cel In rng
FGL = cel.Offset(0, 3).Value
ur = Worksheets(FGL).Cells(Rows.Count, 1).End(xlUp).Row
Range("A" & cel.Row & ":" & "d" & cel.Row).Copy Destination:=Worksheets(FGL).Range("A" & ur + 1)
Next cel
End Sub |
Sub SuddividiPerFogli()
Dim i As Integer
Dim CL As Range, Intervallo As Range, Elenco As New Collection
Dim Valori As Variant
Dim rng As Range
Dim cel As Range
Dim ur As Long
Dim lr As Long
Dim FGL As String
Worksheets("Foglio1").Select
Set Intervallo = Range("d1", Range("d1").End(xlDown))
On Error Resume Next
For Each CL In Intervallo
Elenco.Add CL.Value, CStr(CL.Value)
Next
On Error GoTo 0
For i = 1 To Elenco.Count
ThisWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
Next
For i = 1 To Elenco.Count
Sheets(i + 1).Name = Elenco(i)
Next i
For i = 2 To Sheets.Count
Sheets(i).Cells(1, 1).Value = "NOME"
Sheets(i).Cells(1, 2).Value = "COGNOME"
Sheets(i).Cells(1, 3).Value = "ETA"
Sheets(i).Cells(1, 4).Value = "LUOGO"
Next i
Worksheets("Foglio1").Activate
Set rng = Range("a1:a" & Cells(Rows.Count, 1).End(xlUp).Row)
For Each cel In rng
FGL = cel.Offset(0, 3).Value
ur = Worksheets(FGL).Cells(Rows.Count, 1).End(xlUp).Row
Range("A" & cel.Row & ":" & "d" & cel.Row).Copy Destination:=Worksheets(FGL).Range("A" & ur + 1)
Next cel
End Sub
|
1 Sub Macro1()
2 Dim rng As Range
3 Dim cel As Range
4 Dim ur As Long
5 Dim lr As Long
6 Set rng = Range("D1:D" & Cells(Rows.Count, 1).End(xlUp).Row)
7 Application.ScreenUpdating = False
8 For Each cel In rng
9 lr = Worksheets("ESTERE").Cells(Rows.Count, 1).End(xlUp).Row
10 ur = Worksheets("ITALIANE").Cells(Rows.Count, 1).End(xlUp).Row
11 If cel.Value = "LONDRA" Or cel.Value = "BERLINO" Or cel.Value = "MADRID" Then
12 Range("A" & cel.Row & ":" & "d" & cel.Row).Copy Destination:=Worksheets("ESTERE").Range("A" & lr + 1)
13 Else
14 Range("A" & cel.Row & ":" & "d" & cel.Row).Copy Destination:=Worksheets("ITALIANE").Range("A" & ur + 1)
15 End If
16 Next cel
17 Application.ScreenUpdating = True
18 MsgBox "Operazione effettuata"
19 Set rng = Nothing
20 Set cel = Nothing
21 End Sub
|
11 If cel.Value = "LONDRA" Or cel.Value = "BERLINO" Or cel.Value = "MADRID" Then 11 If Trim(cel.Value) = "LONDRA" Or cel.Value = "BERLINO" Or cel.Value = "MADRID" Then |
