ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Working within a workbook without activating it? (https://www.excelbanter.com/excel-programming/310550-working-within-workbook-without-activating.html)

hyyfte[_9_]

Working within a workbook without activating it?
 

This code is extremely ineffecient. It has to activate each workbook t
do every step. Is there a way to work within a file without activatin
it?

Windows("Package Tracking.xls").Activate
Call Sheets(1).Select(True)
r = 2
Do
i = 2
Do Until IsEmpty(Cells(i, 1))
Range(Cells(i, 1), Cells(i, 15)).Select
Selection.Copy
Windows("Master.xls").Activate
Cells(r, 1).Select
ActiveSheet.Paste Link:=True
Cells(r + 1, 1).Select
Windows("Package Tracking.xls").Activate
i = i + 1
r = r + 1
Loop
ActiveSheet.Next.Select
On Error GoTo Format
Loo

--
hyyft
-----------------------------------------------------------------------
hyyfte's Profile: http://www.excelforum.com/member.php...fo&userid=1318
View this thread: http://www.excelforum.com/showthread.php?threadid=26156


Bernie Deitrick

Working within a workbook without activating it?
 
hyyfte,

You seem to be looping through and making links row by row. It would be much
more efficient to change

Range(Cells(i, 1), Cells(i, 15)).Select
Selection.Copy

to

Range(Cells(i, 1), Cells(Cells(65536,1).End(xlUp).Row, 15)).Copy

(NB. This will only work if you don't have any filled in cells below your
block of cells in column A)

Then get rid of the "Do Until IsEmpty(Cells(i, 1))" loop.

HTH,
Bernie
MS Excel MVP

"hyyfte" wrote in message
...

This code is extremely ineffecient. It has to activate each workbook to
do every step. Is there a way to work within a file without activating
it?

Windows("Package Tracking.xls").Activate
Call Sheets(1).Select(True)
r = 2
Do
i = 2
Do Until IsEmpty(Cells(i, 1))
Range(Cells(i, 1), Cells(i, 15)).Select
Selection.Copy
Windows("Master.xls").Activate
Cells(r, 1).Select
ActiveSheet.Paste Link:=True
Cells(r + 1, 1).Select
Windows("Package Tracking.xls").Activate
i = i + 1
r = r + 1
Loop
ActiveSheet.Next.Select
On Error GoTo Format
Loop


--
hyyfte
------------------------------------------------------------------------
hyyfte's Profile:

http://www.excelforum.com/member.php...o&userid=13187
View this thread: http://www.excelforum.com/showthread...hreadid=261569





All times are GMT +1. The time now is 06:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com