
Option Explicit
Sub Unione()
Dim sh1 As Worksheet: Set sh1 = Sheets("Foglio1") ' da cambiare casomai
Dim sh2 As Worksheet: Set sh2 = Sheets("Foglio2") ' da cambiare casomai
Dim sh3 As Worksheet: Set sh3 = Sheets("Foglio3") ' da cambiare casomai
Dim Area2 As Range
Dim Uriga1 As Long, Uriga2 As Long, RR As Long, X As Long, R As Long
Dim Nome As String, Riga As Object, Prezzo1 As Double, Prezzo2 As Double
Uriga1 = sh1.Range("A" & Rows.Count).End(xlUp).Row
Uriga2 = sh2.Range("A" & Rows.Count).End(xlUp).Row
Set Area2 = sh2.Range("A2:A" & Uriga2)
RR = 2
For X = 2 To Uriga1
Nome = sh1.Cells(X, 1)
Prezzo1 = sh1.Cells(X, 3)
Set Riga = Area2.Find(Nome, LookIn:=xlValues, LookAt:=xlWhole)
If Riga Is Nothing Then
sh1.Range(sh1.Cells(X, 1), sh1.Cells(X, 3)).Copy
sh3.Cells(RR, 1).PasteSpecial
RR = RR + 1
Else
R = Riga.Row
Prezzo2 = sh2.Cells(R, 3)
If Prezzo1 <= Prezzo2 Then
sh1.Range(sh1.Cells(X, 1), sh1.Cells(X, 3)).Copy
sh3.Cells(RR, 1).PasteSpecial
RR = RR + 1
Else
sh2.Range(sh2.Cells(R, 1), sh2.Cells(R, 3)).Copy
sh3.Cells(RR, 1).PasteSpecial
RR = RR + 1
End If
End If
Next X
Set Area2 = sh1.Range("A2:A" & Uriga1)
For X = 2 To Uriga2
Nome = sh2.Cells(X, 1)
Set Riga = Area2.Find(Nome, LookIn:=xlValues, LookAt:=xlWhole)
If Riga Is Nothing Then
sh2.Range(sh2.Cells(X, 1), sh2.Cells(X, 3)).Copy
sh3.Cells(RR, 1).PasteSpecial
RR = RR + 1
End If
Next X
Set sh1 = Nothing
Set sh2 = Nothing
Set sh3 = Nothing
MsgBox "Fatto"
End Sub
|
Option Explicit
Sub togli()
Dim ur1 As Long, ur2 As Long, ur3 As Long
Sheets(3).Cells.ClearContents
ur1 = Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
ur2 = Sheets(2).Range("A" & Rows.Count).End(xlUp).Row
Sheets(1).Range("A1:C" & ur1).Copy Sheets(3).Range("A1")
ur3 = Sheets(3).Range("A" & Rows.Count).End(xlUp).Row
Sheets(2).Range("A2:C" & ur2).Copy Sheets(3).Range("A" & ur3 + 1)
ur3 = Sheets(3).Range("A" & Rows.Count).End(xlUp).Row
Sheets(3).Range("$A$1:$C$" & ur3).RemoveDuplicates Columns:=1, Header:=xlYes
End Sub |
cella.Value = cella.Value
Option Explicit
Sub togli()
Dim ur1 As Long, ur2 As Long, ur3 As Long
Dim c As Range, xcell As Range
Dim stringa As String, i As Long
Sheets(3).Cells.ClearContents
Application.ScreenUpdating = False
ur1 = Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
ur2 = Sheets(2).Range("A" & Rows.Count).End(xlUp).Row
Sheets(1).Range("A1:Z" & ur1).Copy Sheets(3).Range("A1")
ur3 = Sheets(3).Range("A" & Rows.Count).End(xlUp).Row
Sheets(2).Range("A2:Z" & ur2).Copy Sheets(3).Range("A" & ur3 + 1)
ur3 = Sheets(3).Range("A" & Rows.Count).End(xlUp).Row
Sheets(3).Activate
For i = 2 To ur3
stringa = Cells(i, 1).Value
If stringa = "" Then Exit For
Set xcell = Sheets(3).Range(Cells(i + 1, 1), Cells(ur3, 1)).Find(What:=stringa, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not xcell Is Nothing Then
If Cells(i, 1).Offset(, 2) >= xcell.Offset(, 2) Then
Cells(i, 1).EntireRow.Delete
Else
xcell.EntireRow.Delete
End If
End If
Next i
Application.ScreenUpdating = True
MsgBox "Fatto"
End Sub |
Option Explicit
Sub Unione()
Dim sh1 As Worksheet: Set sh1 = Sheets("Foglio1") ' da cambiare casomai
Dim sh2 As Worksheet: Set sh2 = Sheets("Foglio2") ' da cambiare casomai
Dim sh3 As Worksheet: Set sh3 = Sheets("Foglio3") ' da cambiare casomai
Dim Area3 As Range
Dim Uriga1 As Long, Uriga2 As Long, RR As Long, X As Long, R As Long
Dim Nome As String, Riga As Object
Dim T As Single ' calcola tempo
T = Timer ' calcola tempo
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
sh3.Cells.ClearContents
Uriga1 = sh1.Range("A" & Rows.Count).End(xlUp).Row
Uriga2 = sh2.Range("A" & Rows.Count).End(xlUp).Row
sh2.Range(sh2.Cells(2, 1), sh2.Cells(Uriga2, 26)).Copy
sh3.Cells(2, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Set Area3 = sh3.Range("A2:A" & Uriga2)
RR = Uriga2 + 1
For X = 2 To Uriga1
Nome = sh1.Cells(X, 1)
Set Riga = Area3.Find(Nome, LookIn:=xlValues, LookAt:=xlWhole)
If Riga Is Nothing Then
sh1.Range(sh1.Cells(X, 1), sh1.Cells(X, 26)).Copy
sh3.Cells(RR, 1).PasteSpecial
RR = RR + 1
Else
R = Riga.Row
If sh1.Cells(X, 3) < sh3.Cells(R, 3) Then
sh3.Cells(R, 3) = sh1.Cells(X, 3)
End If
End If
Next X
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
MsgBox "Unione complettata in :" & " " & Timer - T & " " & " minuti/secondi" ' calcola tempo
Set sh1 = Nothing
Set sh2 = Nothing
Set sh3 = Nothing
End Sub |
sh3.Range("AA2:AA" & Uriga2) = "foglio2"
|
Else
R = Riga.Row
If sh1.Cells(X, 3) < sh3.Cells(R, 3) Then
sh3.Cells(R, 3) = sh1.Cells(X, 3)
---------->sh3.cells(R,27) = "Foglio1"
End If |
