Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 113
Default on _SelectionChange Copy Range to Second Worksheet

I have 2 worksheets. Whenever the active cell is changed in sheet 1 I want to copy the contents of the current row plus the next 5 rows to the top of Worksheet 2. Depending on what row is active will determine where the row selection will start for the copy.

I am using VB and Excel 2002

Thanks in advance - Dan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default on _SelectionChange Copy Range to Second Worksheet

Dan,

Does this do what you want?

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)

If Sh.Name = "Sheet1" Then
Target.EntireRow.Resize(6).Copy _
Destination:=Sheet2.Range("A1")
End If

End Sub

hth,

Doug

"Dan" wrote in message
...
I have 2 worksheets. Whenever the active cell is changed in sheet 1 I want

to copy the contents of the current row plus the next 5 rows to the top of
Worksheet 2. Depending on what row is active will determine where the row
selection will start for the copy.

I am using VB and Excel 2002.

Thanks in advance - Dan



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default on _SelectionChange Copy Range to Second Worksheet

How about this

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Target.Range("A1:A6").EntireRow.Copy
Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1
0).PasteSpecial
Target.Offset(100, 0).Range("A1:A6").EntireRow.Copy
Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1
0).PasteSpecial
End Sub

placed in the worksheet you want to copy from

Davi

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default on _SelectionChange Copy Range to Second Worksheet

Dan,

I think the loop was probably because the sheet names I used may not apply
and it was trying to paste into the sheet it copied from. BTW you can stop
a loop with ctrl-break inside Excel (I have a lot of practice!).

Anyways if you paste this code into "Sheet1" it should copy as you want into
"Sheet2". Modify the sheet names to suit your book. To copy into Sheet1
right click on the sheet tab, choose View Code and paste. Note that this
code will crash if you are within 106 rows of the bottom of the sheet (row
65400):

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Target.EntireRow.Resize(6).Copy _
Destination:=Sheet2.Range("A1")
Rows(Target.Row + 100).EntireRow.Resize(6).Copy _
Destination:=Worksheets("Sheet2").Range("A7")

End Sub

hth,

Doug

"Dan" wrote in message
...
Doug,

The code you passed on causes an endless loop which I have to shut down

with task manager. Another feature that I didn't include in the initial post
is that I also want to grab a block of 6 rows a 100 down from the current
location as well and paste this to sheet2.

Thanks for your help - Dan

----- Doug Glancy wrote: -----

Dan,

Does this do what you want?

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal

Target
As Range)

If Sh.Name = "Sheet1" Then
Target.EntireRow.Resize(6).Copy _
Destination:=Sheet2.Range("A1")
End If

End Sub

hth,

Doug

"Dan" wrote in message
...
I have 2 worksheets. Whenever the active cell is changed in sheet 1

I want
to copy the contents of the current row plus the next 5 rows to the

top of
Worksheet 2. Depending on what row is active will determine where the

row
selection will start for the copy.
I am using VB and Excel 2002.
Thanks in advance - Dan






  #5   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 113
Default on _SelectionChange Copy Range to Second Worksheet

Doug

This works great! Thanks for your help and have a good holiday weekend

Regards - Dan


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default on _SelectionChange Copy Range to Second Worksheet

I'm glad to hear it. You too.

Doug

"Dan" wrote in message
...
Doug,

This works great! Thanks for your help and have a good holiday weekend.

Regards - Dan



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 range from one worksheet and paste to multiple worksheets mooring Excel Discussion (Misc queries) 10 January 19th 08 04:19 PM
Copy Range From Multiple Worksheets to a Single Worksheet Dauntless1 Excel Discussion (Misc queries) 5 August 17th 07 01:59 AM
Copy and Paste a Worksheet Range to Email Body Eric[_14_] Excel Programming 1 January 20th 04 12:06 AM
Copy information from a specific range; not the entire worksheet. Paul Excel Programming 9 October 12th 03 03:41 PM
How? Macro to copy range to new worksheet, name new worksheet, loop Repoman Excel Programming 9 October 9th 03 01:45 PM


All times are GMT +1. The time now is 05:45 AM.

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

About Us

"It's about Microsoft Excel"