
Sub a2()
Sheets("Foglio1").Select
LR = Cells(Rows.Count, "A").End(xlUp).Row
FName = Sheets("Comandi").Range("B3") 'Percorso del file
Foglio = Sheets("Comandi").Range("C3") 'Nome del file dove salvare i dati
Range("A6:I" & LR).Copy
Application.DisplayAlerts = False
Set wbdest = Workbooks.Open(FName)
LR = wbdest.Sheets(Foglio).Cells(Rows.Count, "A").End(xlUp).Row + 1
wbdest.Sheets(Foglio).Range("A" & LR).PasteSpecial 'Incolla i dati
Application.CutCopyMode = False
wbdest.Close True
Application.DisplayAlerts = True
End Sub
|
Sub a2()
Sheets("Foglio1").Select
FName = Sheets("Comandi").Range("B3") 'Percorso del file
Foglio = Sheets("Comandi").Range("C3") 'Nome del file dove salvare i dati
Range("B22:B26").Copy
Application.DisplayAlerts = False
Set wbdest = Workbooks.Open(FName)
wbdest.Sheets(Foglio).Range("A23").PasteSpecial 'Incolla i dati
Application.CutCopyMode = False
wbdest.Close True
Application.DisplayAlerts = True
End Sub |
Sub a2()
Set sh1 = ThisWorkbook.Sheets("Foglio1")
sh1.Select
LR = Cells(Rows.Count, "A").End(xlUp).Row
FName = Sheets("Comandi").Range("B3") 'Percorso del file
Foglio = Sheets("Comandi").Range("C3") 'Nome del file dove salvare i dati
'Application.DisplayAlerts = False
Set wbdest = Workbooks.Open(FName)
LR1 = wbdest.Sheets(Foglio).Cells(Rows.Count, "A").End(xlUp).Row + 1
sh1.Range("A6:A" & LR).Copy
wbdest.Sheets(Foglio).Range("A" & LR1).PasteSpecial xlValues
sh1.Range("D6:D" & LR).Copy
wbdest.Sheets(Foglio).Range("B" & LR1).PasteSpecial xlValues
sh1.Range("G6:G" & LR).Copy
wbdest.Sheets(Foglio).Range("D" & LR1).PasteSpecial xlValues
sh1.Range("J6:J" & LR).Copy
wbdest.Sheets(Foglio).Range("F" & LR1).PasteSpecial xlValues
Application.CutCopyMode = False
wbdest.Close True
Application.DisplayAlerts = True
End Sub |
Option Explicit
Sub a2()
Dim sh1 As Worksheet: Set sh1 = Worksheets("Foglio1")
Dim wbdest As Workbook
Dim LR As Long, Lr1 As Long, R As Long, X As Long
Dim FName As String, Foglio As String
Dim Risposta As Integer, RigaA As Object
sh1.Select
LR = Cells(Rows.Count, "A").End(xlUp).Row
FName = Sheets("Comandi").Range("B3") 'Percorso del file
Foglio = Sheets("Comandi").Range("C3") 'Nome del file dove salvare i dati
Set wbdest = Workbooks.Open(FName)
Lr1 = wbdest.Sheets(Foglio).Cells(Rows.Count, "A").End(xlUp).Row + 1
For X = 6 To LR
Set RigaA = wbdest.Sheets(Foglio).Range(wbdest.Sheets(Foglio).Cells(6, 1), wbdest.Sheets(Foglio).Cells(Lr1, 1)).Find(sh1.Cells(X, 1), LookIn:=xlValues, LookAt:=xlWhole)
If RigaA Is Nothing Then
wbdest.Sheets(Foglio).Cells(Lr1, 1) = sh1.Cells(X, 1).Value
wbdest.Sheets(Foglio).Cells(Lr1, 2) = sh1.Cells(X, 4).Value
wbdest.Sheets(Foglio).Cells(Lr1, 4) = sh1.Cells(X, 7).Value
wbdest.Sheets(Foglio).Cells(Lr1, 6) = sh1.Cells(X, 10).Value
Lr1 = Lr1 + 1
Else
R = RigaA.Row
Risposta = MsgBox(prompt:="DATA già presente. Cosa copiare i dati?", Buttons:=vbYesNo)
'avendo trovato la data li sovvrascrive
If Risposta = vbYes Then
wbdest.Sheets(Foglio).Cells(R, 1) = sh1.Cells(X, 1).Value
wbdest.Sheets(Foglio).Cells(R, 2) = sh1.Cells(X, 4).Value
wbdest.Sheets(Foglio).Cells(R, 4) = sh1.Cells(X, 7).Value
wbdest.Sheets(Foglio).Cells(R, 6) = sh1.Cells(X, 10).Value
End If
End If
Next X
wbdest.Close True
Application.DisplayAlerts = True
Set wbdest = Nothing
Set sh1 = Nothing
End Sub
|
Next X Application.DisplayAlerts = False wbdest.Close True |
Option Explicit
Sub a2()
Dim sh1 As Worksheet: Set sh1 = Worksheets("Foglio1")
Dim wbdest As Workbook
Dim LR As Long, Lr1 As Long, R As Long, X As Long
Dim FName As String, Foglio As String
Dim Risposta As Integer, RigaA As Object
sh1.Select
LR = Cells(Rows.Count, "A").End(xlUp).Row
FName = Sheets("Comandi").Range("B3") 'Percorso del file
Foglio = Sheets("Comandi").Range("C3") 'Nome del file dove salvare i dati
Set wbdest = Workbooks.Open(FName)
Lr1 = wbdest.Sheets(Foglio).Cells(Rows.Count, "A").End(xlUp).Row + 1
wbdest.Sheets(Foglio).Range("A6:G" & Lr1).RemoveDuplicates Columns:=1, Header:=xlYes
For X = 6 To LR
Set RigaA = wbdest.Sheets(Foglio).Range(wbdest.Sheets(Foglio).Cells(6, 1), wbdest.Sheets(Foglio).Cells(Lr1, 1)).Find(sh1.Cells(X, 1), LookIn:=xlValues, LookAt:=xlWhole)
If RigaA Is Nothing Then
wbdest.Sheets(Foglio).Cells(Lr1, 1) = sh1.Cells(X, 1).Value
wbdest.Sheets(Foglio).Cells(Lr1, 2) = sh1.Cells(X, 4).Value
wbdest.Sheets(Foglio).Cells(Lr1, 4) = sh1.Cells(X, 7).Value
wbdest.Sheets(Foglio).Cells(Lr1, 6) = sh1.Cells(X, 10).Value
Lr1 = Lr1 + 1
Else
R = RigaA.Row
If wbdest.Sheets(Foglio).Cells(R, 2) <> sh1.Cells(X, 4).Value Or wbdest.Sheets(Foglio).Cells(R, 4) <> sh1.Cells(X, 7).Value Or wbdest.Sheets(Foglio).Cells(R, 6) <> sh1.Cells(X, 10).Value Then
Risposta = MsgBox(prompt:="DATA già presente. Copiare i dati?" & vbCrLf & wbdest.Sheets(Foglio).Cells(R, 2) & " ---> " & sh1.Cells(X, 4).Value & vbCrLf & wbdest.Sheets(Foglio).Cells(R, 4) & " ---> " & sh1.Cells(X, 7).Value & vbCrLf & wbdest.Sheets(Foglio).Cells(R, 6) & " ---> " & sh1.Cells(X, 10).Value, Buttons:=vbYesNo) 'avendo trovato la data li sovvrascrive
If Risposta = vbYes Then
wbdest.Sheets(Foglio).Cells(R, 1) = sh1.Cells(X, 1).Value
wbdest.Sheets(Foglio).Cells(R, 2) = sh1.Cells(X, 4).Value
wbdest.Sheets(Foglio).Cells(R, 4) = sh1.Cells(X, 7).Value
wbdest.Sheets(Foglio).Cells(R, 6) = sh1.Cells(X, 10).Value
End If
End If
End If
Next X
Application.DisplayAlerts = False
wbdest.Close True
Application.DisplayAlerts = True
Set wbdest = Nothing
Set sh1 = Nothing
End Sub
|
