Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Lorenzo,
per quanto riguarda il corso di Excel VBA: credo che il corso migliore si possa frequentare visitando assiduamente le pagine di questo forum. Segui le domande, prova a risolverle, confrontati con le risposte date. Se hai voglia e passione non sarà difficile.
La macro che segue popola il foglio r1 con i valori univoci presenti nel foglio t2 rispetto al foglio t1, e il foglio rf con una lista univoca dei valori presenti su entrambi i foglio t1 e t2.
Sub ListaUnivoca()
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim sh3 As Worksheet
Dim sh4 As Worksheet
Dim colR1 As Collection
Dim colRf As Collection
Dim varItem As Variant
Dim lRiga As Long
Dim i As Long
With ThisWorkbook
Set sh1 = .Worksheets("t1")
Set sh2 = .Worksheets("t2")
Set sh3 = .Worksheets("r1")
Set sh4 = .Worksheets("rf")
End With
Set colR1 = New Collection
Set colRf = New Collection
On Error Resume Next
With sh2
lRiga = .Cells(.Rows.Count, 1).End(xlUp).Row
For i = 2 To lRiga
colR1.Add .Cells(i, 1).Value & "," & .Cells(i, 2).Value _
& "," & .Cells(i, 3).Value, CStr(.Cells(i, 1).Value)
colRf.Add .Cells(i, 1).Value & "," & .Cells(i, 2).Value _
& "," & .Cells(i, 3).Value, CStr(.Cells(i, 1).Value)
Next i
End With
With sh1
lRiga = .Cells(.Rows.Count, 1).End(xlUp).Row
For i = 2 To lRiga
colR1.Remove CStr(.Cells(i, 1).Value)
colRf.Add .Cells(i, 1).Value & "," & .Cells(i, 2).Value _
& "," & .Cells(i, 3).Value, CStr(.Cells(i, 1).Value)
Next i
End With
On Error GoTo 0
i = 2
With sh3
.UsedRange.Resize.Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count).ClearContents
For Each varItem In colR1
.Cells(i, 1).Value = Split(varItem, ",")(0)
.Cells(i, 2).Value = Split(varItem, ",")(1)
.Cells(i, 3).Value = Split(varItem, ",")(2)
i = i + 1
Next varItem
.Columns("A:C").AutoFit
End With
i = 2
With sh4
.UsedRange.Resize.Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count).ClearContents
For Each varItem In colRf
.Cells(i, 1).Value = Split(varItem, ",")(0)
.Cells(i, 2).Value = Split(varItem, ",")(1)
.Cells(i, 3).Value = Split(varItem, ",")(2)
i = i + 1
Next varItem
.Columns("A:C").AutoFit
End With
Set colR1 = Nothing
Set colRf = Nothing
Set sh1 = Nothing
Set sh2 = Nothing
Set sh3 = Nothing
Set sh4 = Nothing
End Sub
David