Copia un intervallo al posto di Activecell in un foglio di database utilizzando VBA in Microsoft Excel

Sommario
  • I codici di esempio verranno copiati in un foglio di database con il nome Sheet2.
  • Ogni volta che esegui uno dei sottotitoli, le celle verranno posizionate sotto l'ultima riga con i dati o dopo l'ultima colonna con i dati nel foglio2.
  • Per ogni esempio c'è una macro che fa una copia normale e una che è solo Copia i valori.
  • I sottotitoli di esempio utilizzano le funzioni seguenti (le macro non funzioneranno senza le funzioni).
Sub CopyToActiveCell() Dim sourceRange As Range Dim destrange As Range If Selection.Cells.Count > 1 Then Exit Sub Imposta sourceRange = Sheets("Sheet1").Range("A1:C10") Imposta destrange = ActiveCell sourceRange.Copy destrange End Sub Sub CopyToActiveCellValues() Dim sourceRange As Range Dim destrange As Range If Selection.Cells.Count > 1 Then Exit Sub Set sourceRange = Sheets("Sheet1").Range("A1:C10") With sourceRange Imposta destrange = ActiveCell.Resize _ (.Rows.Count, .Columns.Count) Termina con destrange.Value = sourceRange.Value End Sub Function LastRow(sh As Worksheet) On Error Resume Next LastRow = sh.Cells.Find(What:="*", _ After:=sh.Range("A1"), _ Lookat:=xlPart, _ LookIn:=xlFormulas, _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious, _ MatchCase:=False).Row On Error GoTo 0 End Function Funzione Lastcol(sh As Worksheet) In caso di errore Riprendi successivo Lastcol = sh.Cells.Find(What:="*", _ After:=sh.Range("A1"), _ Lookat:=xlPart, _ LookIn:=xlFormulas , _ SearchOrder:=xlByColumns, _ SearchDirection:= xlPrevious, _ MatchCase:=False).Column On Error GoTo 0 End Function

Aiuterete lo sviluppo del sito, condividere la pagina con i tuoi amici

wave wave wave wave wave