Ciao Antonio,
Ho creato un modulo che aggiorna una tabella (copiando e incollando i dati) che ho implementato in seguito in una macro più complessa. Ma c'è un problema: devo far si che ogni volta che clicco il bottone che avvia la macro, i dati vengano automaticamente
inseriti nella prima riga vuota.
Vi posto il codice del modulo al quale andrebbe aggiunto una specie di contatore (o un ciclo) che mi permettano di effettuare questo aggiornamento.
Grazie per la disponibilità,
A. Paradiso
Ecco l codice:
Sub aggStorico()
'
' aggStorico Macro
'
'
ActiveCell.FormulaR1C1 = "=Preventivi!R[42]C[-6]"
Range("G11").Select
Sheets("Preventivi").Select
Range("B52").Select
ActiveCell.FormulaR1C1 = "='Stampa Preventivo'!R[-42]C[1]"
Range("C52").Select
ActiveCell.FormulaR1C1 = "='Stampa Preventivo'!R[-41]C"
Range("D52").Select
ActiveCell.FormulaR1C1 = "='Stampa Preventivo'!R[-37]C[-3]"
Range("E52").Select
ActiveCell.FormulaR1C1 = "='Stampa Preventivo'!R[-37]C[-3]"
Range("F52").Select
ActiveCell.FormulaR1C1 = "='Stampa Preventivo'!R[-17]C[1]"
Range("F53").Select
End Sub
Prova qualcosa del genere:
'=========>>
Option Explicit
'--------->>
Public Sub Tester()
Dim WB As Workbook
Dim srcSH As Worksheet, destSH As Worksheet
Dim destRng As Range
Dim LRow As Long
Const sFoglio_Destinazione As String = "Preventivi"
ActiveCell.FormulaR1C1 = "=Preventivi!R[42]C[-6]"
Set WB = ThisWorkbook
Set destSH = WB.Sheets(sFoglio_Destinazione)
LRow = LastRow(destSH, .Columns("A:A"))
With destSH
.Cells(LRow + 1, "B").FormulaR1C1 = "='Stampa Preventivo'!R[-42]C[1]"
.Cells(LRow + 1, "C").FormulaR1C1 = "='Stampa Preventivo'!R[-41]C"
.Cells(LRow + 1, "D").FormulaR1C1 = "='Stampa Preventivo'!R[-37]C[-3]"
.Cells(LRow + 1, "E").FormulaR1C1 = "='Stampa Preventivo'!R[-37]C[-3]"
.Cells(LRow + 1, "F").FormulaR1C1 = "='Stampa Preventivo'!R[-17]C[1]"
End With
End Sub
'--------->>
Public Function LastRow(SH As Worksheet, _
Optional rng As Range, _
Optional minRow As Long = 1, _
Optional sPassword As String)
Dim bProtected As Boolean
With SH
If rng Is Nothing Then
Set rng = .Cells
End If
bProtected = .ProtectContents = True
If bProtected Then
Application.ScreenUpdating = False
.Unprotect Password:=sPassword
End If
End With
On Error Resume Next
LastRow = rng.Find(What:="*", _
after:=rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
If LastRow < minRow Then
LastRow = minRow
End If
If bProtected Then
SH.Protect Password:=sPassword, _
UserInterfaceOnly:=True
End If
Application.ScreenUpdating = True
End Function
'<<=========
===
Regards,
Norman
