
Option Explicit
Sub tre_condizioni_vecchiofrac()
Dim ur As Long, tab1 As Range, x As Range
Dim ciclo1 As Range, ciclo2 As Range, s1 As String, s2 As String
Sheets("foglio1").[P:P].ClearContents
Application.ScreenUpdating = False
With Sheets("foglio1")
ur = .[B1].Cells(Rows.Count, 2).End(xlUp).Row ' trovo ultima riga
Set tab1 = Range(.Cells(2, 2), .Cells([COUNTA(B:B)] + 1, 2)) 'range colonna b fino ultima riga
End With
'scorri dalla prima riga alla penultima, escludendo l'intestazione della tabella
For Each ciclo1 In tab1.Offset(1).Resize(tab1.Rows.Count - tab1(1).Row)
'controlla che non abbiamo già processato la riga
If ciclo1.Offset(, 14) <> "trovato" Then
s1 = Trim(ciclo1) & Trim(ciclo1.Offset(, 2)) & Trim(ciclo1.Offset(, 5))
'scorri dalla cella successiva a quella attiva in ciclo1 fino alla fine della tabella
For Each ciclo2 In tab1(ciclo1.Row).Resize(tab1.Rows.Count - 1, 1)
'controlla che non abbiamo già processato la riga
If ciclo2.Offset(, 14) <> "trovato" Then
s2 = Trim(ciclo2) & Trim(ciclo2.Offset(, 2)) & Trim(ciclo2.Offset(, 5))
If (s1 & s2 <> "") And s1 = s2 Then
ciclo1.Offset(, 14) = "trovato" 'scrivi "trovato" in colonna P
ciclo2.Offset(, 14) = "trovato" 'scrivi "trovato" in colonna P
End If
End If
Next
End If
Next
[A1].Select
Application.ScreenUpdating = True
MsgBox "Ho terminato"
End Sub |
Option Explicit
Sub tre_condizioni_vecchiofrac2()
Dim pr As Long, ur As Long, tab1 As Range
Dim r As Long, v(1 To 3) As Variant
Sheets("foglio1").[P:P].ClearContents
Application.ScreenUpdating = False
With Sheets("foglio1")
pr = .[B1].End(xlDown).Row 'prima riga della tabella (campi di intestazione tabella)
ur = .Cells(Rows.Count, 2).End(xlUp).Row 'ultima riga
Set tab1 = Range(.Cells(pr, 2), .Cells(ur, 2)) 'range colonna b fino ultima riga compilata (comprende eventuali righe vuote)
End With
For r = tab1.Rows.Count To 1 Step -1
v(1) = tab1.Cells(r, 1) 'colonna 1
v(2) = tab1.Cells(r, 3) 'colonna 3
v(3) = tab1.Cells(r, 6) 'colonna 6
With tab1
If WorksheetFunction.CountIf(.Columns(1), v(1)) > 1 And WorksheetFunction.CountIf(.Columns(3), v(2)) > 1 And _
WorksheetFunction.CountIf(.Columns(6), v(3)) > 1 Then
tab1.Rows(r).Cells(, 15) = "trovato"
End If
End With
Next
[A1].Select
Application.ScreenUpdating = True
MsgBox "Ho terminato"
End Sub |
Sub tre_condizioni_vecchiofrac2()
Dim pr As Long, ur As Long, tab1 As Range
Dim r As Long, v(1 To 3) As Variant
Sheets("confronto").[P:P].ClearContents
Application.ScreenUpdating = False
With Sheets("confronto")
ur = .Cells(Rows.Count, 2).End(xlUp).Row 'ultima riga
Set tab1 = Range(.Cells(2, 2), .Cells(ur, 2)) 'range colonna b fino ultima riga compilata (comprende eventuali righe vuote)
End With
For r = tab1.Rows.Count To 1 Step -1
v(1) = tab1.Cells(r, 1) 'colonna 1
v(2) = tab1.Cells(r, 3) 'colonna 3
v(3) = tab1.Cells(r, 6) 'colonna 6
With tab1
If WorksheetFunction.CountIf(.Columns(1), v(1)) > 1 And WorksheetFunction.CountIf(.Columns(3), v(2)) > 1 And _
WorksheetFunction.CountIf(.Columns(6), v(3)) > 1 Then
tab1.Rows(r).Cells(, 15) = "trovato"
End If
End With
Next
[A1].Select
Application.ScreenUpdating = True
MsgBox "Ho terminato"
End Sub |
Option Explicit
Sub tre_condizioni_vecchiofrac2()
Dim ur As Long, tab1 As Range
Dim r As Long, v(1 To 3) As Variant
Dim somma As Double, casa As Double
Sheets("confronto").[P:P].ClearContents
Application.ScreenUpdating = False
With Sheets("confronto")
ur = .Cells(Rows.Count, 2).End(xlUp).Row 'ultima riga
Set tab1 = Range(.Cells(2, 2), .Cells(ur, 2)) 'range colonna b fino ultima riga compilata (comprende eventuali righe vuote)
End With
For r = tab1.Rows.Count To 1 Step -1
v(1) = tab1.Cells(r, 1) 'colonna 1
v(2) = tab1.Cells(r, 3) 'colonna 3
v(3) = tab1.Cells(r, 6) 'colonna 6
With tab1
If WorksheetFunction.CountIf(.Columns(1), v(1)) > 1 And WorksheetFunction.CountIf(.Columns(3), v(2)) > 1 And _
WorksheetFunction.CountIf(.Columns(6), v(3)) > 1 Then
somma = somma + tab1.Cells(r, 11)
[Q1] = somma
tab1.Cells(r, 16).Formula = "=Q1"
End If
End With
Next
For r = 2 To ur
somma = Cells(r, 17)
If Trim(Cells(r, 17)) <> "" Then Cells(r, 17) = somma
Next
[A1].Select
Application.ScreenUpdating = True
MsgBox "Ho terminato"
End Sub
|
Sub sommapeso()
Dim ur As Long, tab1 As Range, x As Range
Dim ciclo1 As Range, ciclo2 As Range, s1 As String, s2 As String
Application.ScreenUpdating = False
With Sheets("confronto")
ur = .Cells(Rows.Count, 2).End(xlUp).Row ' trovo ultima riga
Set tab1 = Range(.Cells(2, 2), .Cells(ur, 2)) 'range colonna b fino ultima riga
End With
'scorri dalla prima riga alla penultima, escludendo l'intestazione della tabella
For Each ciclo1 In tab1.Offset(1).Resize(tab1.Rows.Count - tab1(1).Row)
'controlla che non abbiamo già processato la riga
If ciclo1.Offset(, 14) <> "trovato" Then
s1 = Trim(ciclo1) & Trim(ciclo1.Offset(, 2)) & Trim(ciclo1.Offset(, 5))
'scorri dalla cella successiva a quella attiva in ciclo1 fino alla fine della tabella
For Each ciclo2 In tab1(ciclo1.Row).Resize(tab1.Rows.Count - 1, 1)
'controlla che non abbiamo già processato la riga
If ciclo2.Offset(, 14) <> "trovato" Then
s2 = Trim(ciclo2) & Trim(ciclo2.Offset(, 2)) & Trim(ciclo2.Offset(, 5))
If (s1 & s2 <> "") And s1 = s2 Then
ciclo1.Offset(, 12).Interior.ColorIndex = 6
ciclo2.Offset(, 12).Interior.ColorIndex = 6
End If
End If
Next
End If
Next
totali
Application.ScreenUpdating = True
End Sub |
Sub sommapeso()
Dim ur As Long, tab1 As Range, x As Range
Dim ciclo1 As Range, ciclo2 As Range, s1 As String, s2 As String
Application.ScreenUpdating = False
With Sheets("confronto")
ur = .Cells(Rows.Count, 2).End(xlUp).Row ' trovo ultima riga
Set tab1 = Range(.Cells(2, 2), .Cells(ur, 2)) 'range colonna b fino ultima riga
End With
For Each ciclo1 In tab1
'controlla che non abbiamo già processato la riga
If ciclo1.Offset(, 14) <> "trovato" Then
s1 = Trim(ciclo1) & Trim(ciclo1.Offset(, 2)) & Trim(ciclo1.Offset(, 5))
'scorri dalla cella successiva a quella attiva in ciclo1 fino alla fine della tabella
For Each ciclo2 In tab1(ciclo1.Row).Resize(tab1.Rows.Count - 1, 1)
'controlla che non abbiamo già processato la riga
If ciclo2.Offset(, 14) <> "trovato" Then
s2 = Trim(ciclo2) & Trim(ciclo2.Offset(, 2)) & Trim(ciclo2.Offset(, 5))
If (s1 & s2 <> "") And s1 = s2 Then
ciclo1.Offset(, 12).Interior.ColorIndex = 6
ciclo2.Offset(, 12).Interior.ColorIndex = 6
End If
End If
Next
End If
Next
totali
Application.ScreenUpdating = True
End Sub |
