Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default copy selected rows to new sheet

My source_sheet contains data that is to be filtered with the accepted row
being copied to target_sheet. Here is a fragment that shows the goal in
pseudo code formatting. Where I have a hard number, code somewhere else has
found that number and provided it.

source_sheet and target_sheet are both Worksheet variables

first_row = 6 ' begin copying with this row
last_row = 134 ' stop copying at this row
target_row = 2 'put first row in row 2 of the target sheet
first_column = 1 ' I have this number if I need it
last_column = 18 ' I have this number if I need it

for source_row = first_row to last_row
If some_condition then
source_sheet.cells( all of row source_row).copy
target_sheet.cels( all of target_row ).paste
target_row = target_row + 1
end if
next source_row

I am not very good at digging through complex Excel syntax so I ask that
responses be in a simple format so I can understand. I need two statements
that do the following:
1) copy all of row number source_row from the source sheet,
2) paste that copied row into the target_sheet in row specified by
target_row

I want to be certain that the question is clear, but this is already too
long. Let me know if clarifications are in order.

Thanks,
Bryan


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default copy selected rows to new sheet

After much serching I pulled some code from someone's posting that uses this
concept. After modifying to meed my needs, I get stuck.

When source_sheet and target_sheet are both set to "Sheet1", this code
works.

When target_sheet is set to "Sheet2", there is an error on this line:

Set target_range = target_sheet.Range(Cells(target_row, 1),
Cells(target_row, 7))

The popup window says:

Run-time error '1004':

Method 'Range' of object '_Worksheet' failed

I have two sheets in the workbook, one named Sheet1 and the other named
Sheet2. Sheet1 has data in the cells of interest while Sheet2 is blank.

What do I need to change to get this to copy to Sheet 2.

Here is the code.

Sub copy_test()

Dim source_sheet As Worksheet

Dim target_sheet As Worksheet

Dim target_row As Integer

Dim source_row As Integer

Dim source_range As Range

Dim target_range As Range

Set source_sheet = Worksheets("Sheet1")

Set target_sheet = Worksheets("Sheet2")

For source_row = 1 To 6

Set source_range = source_sheet.Range(Cells(source_row, 1),
Cells(source_row, 7))

target_row = source_row + 7

Set target_range = target_sheet.Range(Cells(target_row, 1),
Cells(target_row, 7))

source_range.Copy target_range

Next source_row

End Sub

Thanks for your time,

"Bryan" wrote in message
...
My source_sheet contains data that is to be filtered with the accepted row
being copied to target_sheet. Here is a fragment that shows the goal in
pseudo code formatting. Where I have a hard number, code somewhere else
has found that number and provided it.

<snip


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default copy selected rows to new sheet

I was just working on a similar problem. I too was having trouble pasting a
range from 1 sheet to another. I ended up working with cells and cells
offset. I ended up just setting the target cell = to the source cell- no
pasting involved. See if works the same for your target range = source range.
Alfred

"Bryan" wrote:

After much serching I pulled some code from someone's posting that uses this
concept. After modifying to meed my needs, I get stuck.

When source_sheet and target_sheet are both set to "Sheet1", this code
works.

When target_sheet is set to "Sheet2", there is an error on this line:

Set target_range = target_sheet.Range(Cells(target_row, 1),
Cells(target_row, 7))

The popup window says:

Run-time error '1004':

Method 'Range' of object '_Worksheet' failed

I have two sheets in the workbook, one named Sheet1 and the other named
Sheet2. Sheet1 has data in the cells of interest while Sheet2 is blank.

What do I need to change to get this to copy to Sheet 2.

Here is the code.

Sub copy_test()

Dim source_sheet As Worksheet

Dim target_sheet As Worksheet

Dim target_row As Integer

Dim source_row As Integer

Dim source_range As Range

Dim target_range As Range

Set source_sheet = Worksheets("Sheet1")

Set target_sheet = Worksheets("Sheet2")

For source_row = 1 To 6

Set source_range = source_sheet.Range(Cells(source_row, 1),
Cells(source_row, 7))

target_row = source_row + 7

Set target_range = target_sheet.Range(Cells(target_row, 1),
Cells(target_row, 7))

source_range.Copy target_range

Next source_row

End Sub

Thanks for your time,

"Bryan" wrote in message
...
My source_sheet contains data that is to be filtered with the accepted row
being copied to target_sheet. Here is a fragment that shows the goal in
pseudo code formatting. Where I have a hard number, code somewhere else
has found that number and provided it.

<snip



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 selected rows to second worksheet (NOT Cut + Paste) gyrra New Users to Excel 2 June 4th 10 09:05 PM
Copy a selected number of rows Eric S. Excel Discussion (Misc queries) 4 June 25th 07 08:23 AM
Copying selected rows to another sheet tacarme Excel Worksheet Functions 3 June 25th 05 11:46 AM
printing only selected rows in a sheet Wizard Excel Discussion (Misc queries) 0 May 11th 05 06:46 PM
Macro to copy and past selected rows only... Jules[_4_] Excel Programming 1 April 14th 04 02:31 PM


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