Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Copy-Paste between sheets in dif WB's

Hello,

I seem to miss some vital info in how to copy-paste
a selection between one WS in a WB to the WS name in another
WB. I wan to do this in VB and I tried to record a macro
and translate it into my VB-code.
This is what I have done:

Application.ScreenUpdating = False

' Set copy range for WS in secondary WB
mySel = gci_FirstRow_Data & ":" & nLastRowNo
Rows(mySel).Select
' Copy source range
Selection.Copy

' Activate primary WB where the
' selection will be pasted
Windows(sPrimaryPAP).Activate
' Activate and unprotect right worksheet
' where the selection will be pasted
Worksheets(sPrimConfigWSName).Activate
ActiveSheet.Unprotect
' ----- Set paste range in primary WB
mySel = gci_FirstRow_Data & ":" & nLastRowNo
Rows(mySel).Select
' ----- Paste source range
Selection.Insert Shift:=xlDown

' Protect Sheet...
ActiveSheet.Protect

' ... and activate secondary WB
Windows(sSecondWBName).Activate
Worksheets(sSecConfigWSName).Activate

Application.ScreenUpdating = True

Can anybody help me with this. It seems that the range to
be copied are not collected from the other WB.

Thanks in advance!

/konpego
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Copy-Paste between sheets in dif WB's

konpego,

Unprotecting a worksheet clears the clipboard in Excel. See your modified
code below for how to copy to a protected sheet.

HTH,
Bernie
MS Excel MVP

Application.ScreenUpdating = False

' Activate primary WB where the
' selection will be pasted
Windows(sPrimaryPAP).Activate
' Activate and unprotect right worksheet
' where the selection will be pasted
Worksheets(sPrimConfigWSName).Activate
ActiveSheet.Unprotect

' ... and go back and activate secondary WB
Windows(sSecondWBName).Activate
Worksheets(sSecConfigWSName).Activate

' Set copy range for WS in secondary WB
mySel = gci_FirstRow_Data & ":" & nLastRowNo
Rows(mySel).Select
' Copy source range
Selection.Copy

' Re-Activate primary WB where the
' selection will be pasted
Windows(sPrimaryPAP).Activate

' ----- Set paste range in primary WB
mySel = gci_FirstRow_Data & ":" & nLastRowNo
Rows(mySel).Select

' ----- Paste source range
Selection.Insert Shift:=xlDown

' Protect Sheet...
ActiveSheet.Protect

' ... and re-activate secondary WB
Windows(sSecondWBName).Activate
Worksheets(sSecConfigWSName).Activate

Application.ScreenUpdating = True


"konpego" wrote in message
...
Hello,

I seem to miss some vital info in how to copy-paste
a selection between one WS in a WB to the WS name in another
WB. I wan to do this in VB and I tried to record a macro
and translate it into my VB-code.
This is what I have done:

Application.ScreenUpdating = False

' Set copy range for WS in secondary WB
mySel = gci_FirstRow_Data & ":" & nLastRowNo
Rows(mySel).Select
' Copy source range
Selection.Copy

' Activate primary WB where the
' selection will be pasted
Windows(sPrimaryPAP).Activate
' Activate and unprotect right worksheet
' where the selection will be pasted
Worksheets(sPrimConfigWSName).Activate
ActiveSheet.Unprotect
' ----- Set paste range in primary WB
mySel = gci_FirstRow_Data & ":" & nLastRowNo
Rows(mySel).Select
' ----- Paste source range
Selection.Insert Shift:=xlDown

' Protect Sheet...
ActiveSheet.Protect

' ... and activate secondary WB
Windows(sSecondWBName).Activate
Worksheets(sSecConfigWSName).Activate

Application.ScreenUpdating = True

Can anybody help me with this. It seems that the range to
be copied are not collected from the other WB.

Thanks in advance!

/konpego



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Copy-Paste between sheets in dif WB's

Thanks Bernie,

This tip will be useful for me in my future work!
Great!

/konpego


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
Copy and Paste with Macro Between sheets jlclyde Excel Discussion (Misc queries) 1 November 8th 07 05:07 PM
Copy&paste of several sheets Lorenz Excel Discussion (Misc queries) 1 May 29th 07 10:08 PM
copy from one sheet and paste into other sheets TUNGANA KURMA RAJU Excel Discussion (Misc queries) 3 December 8th 05 02:49 PM
copy & paste to all Sheets to the same cells Martyn Excel Programming 2 June 23rd 04 06:42 AM
MS Excel Sheets...how to copy and paste ? tina SPEILBERG Excel Programming 1 August 4th 03 07:15 AM


All times are GMT +1. The time now is 12:33 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"