› Sviluppare funzionalita su Microsoft Office con VBA › Copia-Incolla vba
-
AutoreArticoli
-
Ciao a tutti, devo fare un copia incolla tra due fogli excel diversi.
Ho il seguente codice:
For Each ws In ActiveWorkbook.Worksheets 'Questo for serve per scoprire i fogli nascosti all' interno del file ws.Visible = xlSheetVisible Next ws Sheets("-").Activate Range("T6:AG6").Select Selection.Copy ' Windows("Eca Execution Workload-copia per Andrea.xlsm").Activate ' ThisWorkbook.Sheets("Eca Execution Workload-copia per Andrea.xlsm").Cells(Rows.Count, "AD").End(xlUp).Row ThisWorkbook.Sheets("Eca Execution Workload-copia per Andrea.xlsm").Cells(Rows.Count, "AD").End(xlUp).Row ActiveSheet.Paste Workbooks.Open Filename:=fullPathExcel Sheets("-").Activate ' Windows("xxxx_hrs_report.xlsx").Activate ActiveWindow.CloseCon il ciclo for scopro il foglio dal quale andrò a selezionare le celle.
Il codice mi da un errore di tipo: Run time '9' --> indice non incluso nell' intervallo. E l' errore è segnalato nella riga "ThisWorkbook.Sheets("Eca Execution Workload-copia per Andrea.xlsm").Cells(Rows.Count, "AD").End(xlUp).Row".
Qualcuno da dirmi il perchè dell' errore?
L'errore sta nell'uso di Row
guarda l'help
che dice "Returns the number of the first row of the first area in the range. Read-only Long ."
Se ti ritorna un valore la usata come parte di una funzione o assegnata ad una variabile
prova con pippo=ThisWorkbook.Sheets("Eca Execution Workload-copia per Andrea.xlsm").Cells(Rows.Count, "AD").End(xlUp).Row
oppure
if ThisWorkbook.Sheets("Eca Execution Workload-copia per Andrea.xlsm").Cells(Rows.Count, "AD").End(xlUp).Row = 3 then
Non capisco cosa volevi fare.
Secondo me volevi in qualche maniera selezionare un range per incollare....
Fai sapere Ciao
Luca
Si Luca, volevo selezionare un range per incollare, ma ho trovato una soluzione migliore.
If fullPathExcel <> "" Then Workbooks.Open Filename:=fullPathExcel For Each ws In ActiveWorkbook.Worksheets 'Questo for serve per scoprire i fogli nascosti ws.Visible = xlSheetVisible Next ws Sheets("-").Activate Range("T6:AG6").Select Selection.Copy ' Windows("Eca Execution Workload-copia per Andrea.xlsm").Activate ThisWorkbook.Activate 'Cells(Rows.Count, "AD").End(xlUp).Row ' Range("AD6").Select Range("AD" & intI).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False 'ActiveSheet.Paste Workbooks.Open Filename:=fullPathExcel Sheets("-").Activate ActiveWindow.Close Exit For End If -
AutoreArticoli
