Sub FormattaTabella()
Dim lastRow As Integer
Dim RigaTest As Integer
Dim lastColumn As Long
Dim rng As Range
Dim ColonnaTest As Integer
Dim RigaCancellata As Boolean
Application.ScreenUpdating = False
Range("A2").Select
Set rng = ActiveSheet.UsedRange
lastRow = rng(rng.Count).Row
lastColumn = rng(rng.Count).Column
'lastRow = Cells(Rows.Count, "A").End(xlUp).Row
'lastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
For i = 2 To lastRow
'Do While ActiveCell.Value <> ""
'ogni "CodiceFiscale" (i) verrà confrontato con tutti gli altri (j)
If Cells(i, 11).Value <> "" Then ColonnaTest = Cells(i, 11).Column
If Cells(i, 12).Value <> "" Then ColonnaTest = Cells(i, 12).Column
RigaTest = Cells(i, ColonnaTest).Row
For j = 2 To lastRow
Cells(j, ColonnaTest).Select
If Cells(i, ColonnaTest).Value = Cells(j, ColonnaTest).Value And Cells(j, ColonnaTest).Row <> RigaTest And Cells(i, 2).Value = Cells(j, 2).Value Then
'If ActiveCell.Value = Cells(j, 1).Value And Cells(j, 1).Row <> CellaTest Then
For k = 1 To lastColumn
'Cells(i, k).Font.Bold = True
Cells(j, k).Select
If Cells(i, k).Value <> Cells(j, k).Value And Cells(j, k).Value = "" Then
Cells(i, k).Copy Destination:=ActiveSheet.Cells(j, k)
End If
Next k
Cells(i, 1).EntireRow.Delete
i = i - 1
'If RigaCancellata = True Then Exit For
'esce dal FOR j
Exit For
'Else
'If Cells(j, ColonnaTest).Value = "" Then Exit For
End If
'If Cells(j, 1).Row > CellaTest Then Exit For
Next j
'esce dal FOR i
If Cells(i + 1, 11).Value = "" And Cells(i + 1, 12).Value = "" Then Exit For
'ActiveCell.Offset(1, 0).Select
'Loop
Next i
End Sub
|