Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy & Paste code more efficient


Hi all,
In an effort to make this code shorter and more efficient i am
attempting to rewrite it.
It copies a range from one workbook and pastes into another workbook.
I have several blocks of code like this.

Any suggestions appreciated.

Original:
'Copy and paste site data
Windows("UCPSITE-06.xls").Activate
Sheets("UCP SITE - Totals").Select
Range("BJ5:BJ617").Select
Selection.Copy
Windows("3140UCP2006WithShell.xls").Activate
Sheets("UCP All Site Rankings").Select
Range("I2").Select
ActiveSheet.Paste
'Clears Clipboard
Application.CutCopyMode = False

New:
'Copy and paste site data
Windows("UCPSITE-06.xls").Activate
Sheets("UCP SITE - Totals").Range("BJ5:BJ617").Copy
Windows("3140UCP2006WithShell.xls").Activate
Sheets("UCP All Site Rankings").Range("I2").Paste
'Clears Clipboard
Application.CutCopyMode = False


--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=571946

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Copy & Paste code more efficient

This is even leaner:

Workbooks("UCPSITE-06.xls").Sheets("UCP SITE -
Totals").Range("BJ5:BJ617").Copy
Destination:=Workbooks("3140UCP2006WithShell.xls") .Sheets("UCP All Site
Rankings").Range("I2")
--
3c


"Desert Piranha" wrote:


Hi all,
In an effort to make this code shorter and more efficient i am
attempting to rewrite it.
It copies a range from one workbook and pastes into another workbook.
I have several blocks of code like this.

Any suggestions appreciated.

Original:
'Copy and paste site data
Windows("UCPSITE-06.xls").Activate
Sheets("UCP SITE - Totals").Select
Range("BJ5:BJ617").Select
Selection.Copy
Windows("3140UCP2006WithShell.xls").Activate
Sheets("UCP All Site Rankings").Select
Range("I2").Select
ActiveSheet.Paste
'Clears Clipboard
Application.CutCopyMode = False

New:
'Copy and paste site data
Windows("UCPSITE-06.xls").Activate
Sheets("UCP SITE - Totals").Range("BJ5:BJ617").Copy
Windows("3140UCP2006WithShell.xls").Activate
Sheets("UCP All Site Rankings").Range("I2").Paste
'Clears Clipboard
Application.CutCopyMode = False


--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=571946


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Copy & Paste code more efficient

Try this

Workbooks("UCPSITE-06.xls").Sheets("UCP SITE - Totals").Range("BJ5:BJ617").Copy _
Workbooks("3140UCP2006WithShell.xls").Sheets("UCP All Site Rankings").Range("I2")



--
Regards Ron de Bruin
http://www.rondebruin.nl



"Desert Piranha" <Desert.Piranha.2clm8j_1155674113.3466@excelforu m-nospam.com wrote in message
news:Desert.Piranha.2clm8j_1155674113.3466@excelfo rum-nospam.com...

Hi all,
In an effort to make this code shorter and more efficient i am
attempting to rewrite it.
It copies a range from one workbook and pastes into another workbook.
I have several blocks of code like this.

Any suggestions appreciated.

Original:
'Copy and paste site data
Windows("UCPSITE-06.xls").Activate
Sheets("UCP SITE - Totals").Select
Range("BJ5:BJ617").Select
Selection.Copy
Windows("3140UCP2006WithShell.xls").Activate
Sheets("UCP All Site Rankings").Select
Range("I2").Select
ActiveSheet.Paste
'Clears Clipboard
Application.CutCopyMode = False

New:
'Copy and paste site data
Windows("UCPSITE-06.xls").Activate
Sheets("UCP SITE - Totals").Range("BJ5:BJ617").Copy
Windows("3140UCP2006WithShell.xls").Activate
Sheets("UCP All Site Rankings").Range("I2").Paste
'Clears Clipboard
Application.CutCopyMode = False


--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=571946



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy & Paste code more efficient


Ron & Carlo,

All i can say is WOW.

Workbooks("UCPSITE-06.xls").Sheets("UCP SITE -
Totals").Range("BJ5:BJ617").Copy _
Workbooks("3140UCP2006WithShell.xls").Sheets("UCP All Site
Rankings").Range("I2")

Excellent, Thx very much


--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=571946

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy & Paste code more efficient


Hi,

The code you guys gave works wonderfully, but in another part of the
workbook where i am doing
the same thing i have to "Paste Special" because i just want the values
and not the format & formulas.

So how do i add the Paste Special to the lines you gave me?

Original:
Windows("UCPSITE-06.xls").Activate
' Range("BK227:BK304").Select
' Selection.Copy
' Windows("3140UCP2006WithShell.xls").Activate
' Range("BK3").Select
' Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
' False, Transpose:=False


After:
Workbooks("UCPSITE-06.xls").Sheets("UCP SITE -
Totals").Range("BK227:BK304").Copy _
Workbooks("3140UCP2006WithShell.xls").Sheets("3140 UCP Totals
2006").Range("BK3").PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= False, Transpose:=False


--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=571946



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Copy & Paste code more efficient

Drop the continuation character:

Workbooks("UCPSITE-06.xls").Sheets("UCP SITE - Totals") _
.Range("BK227:BK304").Copy

'new line of code!
Workbooks("3140UCP2006WithShell.xls")
.Sheets("3140 UCP Totals 2006").Range("BK3").PasteSpecial _
Paste:=xlValues, Operation:=xlNone, SkipBlanks:= False, Transpose:=False

Desert Piranha wrote:

Hi,

The code you guys gave works wonderfully, but in another part of the
workbook where i am doing
the same thing i have to "Paste Special" because i just want the values
and not the format & formulas.

So how do i add the Paste Special to the lines you gave me?

Original:
Windows("UCPSITE-06.xls").Activate
' Range("BK227:BK304").Select
' Selection.Copy
' Windows("3140UCP2006WithShell.xls").Activate
' Range("BK3").Select
' Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
' False, Transpose:=False

After:
Workbooks("UCPSITE-06.xls").Sheets("UCP SITE -
Totals").Range("BK227:BK304").Copy _
Workbooks("3140UCP2006WithShell.xls").Sheets("3140 UCP Totals
2006").Range("BK3").PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= False, Transpose:=False

--
Desert Piranha

------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=571946


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Copy & Paste code more efficient

Another thing you might want to look at is the constant re-referencing of
objects, I.e.
Windows("UCPSITE-06.xls").ACTIVATE
' Range("BK227:BK304").SELECT
' Selection.Copy
' Windows("3140UCP2006WithShell.xls").ACTIVATE
' Range("BK3").SELECT


I've noticed this on quite a number of the posts and it obviously comes from
using the macro recorder. However, it really slows down your program and it
hides the object browser. So for example, if you swipe out the ".Select"
after the Range refernce (Range("BK3").Select) and then re-typed in the dot
after the object, you will see the object's properties and methods. That's a
really big bonus in establishing that a) you are using the right object and
or a valid object and b) you can quickly see what methods/properties etc are
availiable to use.

--
3c


"Desert Piranha" wrote:


Hi,

The code you guys gave works wonderfully, but in another part of the
workbook where i am doing
the same thing i have to "Paste Special" because i just want the values
and not the format & formulas.

So how do i add the Paste Special to the lines you gave me?

Original:
Windows("UCPSITE-06.xls").Activate
' Range("BK227:BK304").Select
' Selection.Copy
' Windows("3140UCP2006WithShell.xls").Activate
' Range("BK3").Select
' Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
' False, Transpose:=False


After:
Workbooks("UCPSITE-06.xls").Sheets("UCP SITE -
Totals").Range("BK227:BK304").Copy _
Workbooks("3140UCP2006WithShell.xls").Sheets("3140 UCP Totals
2006").Range("BK3").PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= False, Transpose:=False


--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=571946


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy & Paste code more efficient


Hi Dave,

Thx this works great.

Drop the continuation character:

Workbooks("UCPSITE-06.xls").Sheets("UCP SITE - Totals") _
Range("BK227:BK304").Copy

'new line of code!
Workbooks("3140UCP2006WithShell.xls")
Sheets("3140 UCP Totals 2006").Range("BK3").PasteSpecial _
Paste:=xlValues, Operation:=xlNone, SkipBlanks:= False,
Transpose:=False

Carlos,
Thx, Yeah, its easy to see i'm useing the recorder. i'm trying to do it
on my own,
rather than just asking someone to write it for me. Thx for your help.

Ron,
Thx for your help.

I got a whole pargraph of code to a couple lines.


--
Desert Piranha


------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=571946

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
More efficient copy/paste?? Celt[_64_] Excel Programming 6 June 9th 06 07:21 PM
Efficient Copy/Paste William Benson[_2_] Excel Programming 4 September 8th 05 07:42 PM
Efficient Code GregR Excel Programming 7 June 27th 05 04:09 PM
More Efficient code than this thom hoyle Excel Programming 14 May 11th 05 07:40 AM
More efficient method to copy-paste values in place? quartz[_2_] Excel Programming 4 November 15th 04 01:54 PM


All times are GMT +1. The time now is 06:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"