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

I want to save rows that match a certain criteria to a new worksheet. When I
complete the task, I want to save that worksheet to a file.

I create the worksheet like this:

Set new_xls = Worksheets.Add
new_xls.Move after:=Worksheets(Worksheets.Count)

The move is to put it at the end of the workbook, though I suppose I could
have done it in a single line of code when I created it.

The problem I have is that when I select the data and copy it only works the
first time through the loop. I get an appication error the second time I
paste. (The first time things seem to work properly.

For Each qb In qb_range
If qb.Offset(0, 13) rav_rat Then

better = better + 1#
qb.EntireRow.Copy
ActiveSheet.Paste Destination:=new_xls.Cells(1, Int(better))
If qb_list = "" Then
qb_list = qb_list & Mid(qb.Value, 1, Len(qb.Value) - 7) &
vbCrLf
Else
qb_list = qb_list & " &" & Mid(qb.Value, 1, Len(qb.Value) -
7) & vbCrLf
End If

Else
worse = worse + 1#
End If
Next qb

What am I doing wrong?

Thanks,
David


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default copy selected rows to a new worksheet

You can give this a try...

For Each qb In qb_range
If qb.Offset(0, 13) rav_rat Then

better = better + 1
qb.EntireRow.Copy Destination:=new_xls.Cells(better, 1)
If qb_list = "" Then
qb_list = qb_list & Mid(qb.Value, 1, Len(qb.Value) - 7) &
vbCrLf
Else
qb_list = qb_list & " &" & Mid(qb.Value, 1, Len(qb.Value) -
7) & vbCrLf
End If

Else
worse = worse + 1#
End If
Next qb

--
HTH...

Jim Thomlinson


"David Gerstman" wrote:

I want to save rows that match a certain criteria to a new worksheet. When I
complete the task, I want to save that worksheet to a file.

I create the worksheet like this:

Set new_xls = Worksheets.Add
new_xls.Move after:=Worksheets(Worksheets.Count)

The move is to put it at the end of the workbook, though I suppose I could
have done it in a single line of code when I created it.

The problem I have is that when I select the data and copy it only works the
first time through the loop. I get an appication error the second time I
paste. (The first time things seem to work properly.

For Each qb In qb_range
If qb.Offset(0, 13) rav_rat Then

better = better + 1#
qb.EntireRow.Copy
ActiveSheet.Paste Destination:=new_xls.Cells(1, Int(better))
If qb_list = "" Then
qb_list = qb_list & Mid(qb.Value, 1, Len(qb.Value) - 7) &
vbCrLf
Else
qb_list = qb_list & " &" & Mid(qb.Value, 1, Len(qb.Value) -
7) & vbCrLf
End If

Else
worse = worse + 1#
End If
Next qb

What am I doing wrong?

Thanks,
David


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

Thank you. So in paste I confused row and column.
Sigh.
Again many thanks,
David

"Jim Thomlinson" wrote:

You can give this a try...

For Each qb In qb_range
If qb.Offset(0, 13) rav_rat Then

better = better + 1
qb.EntireRow.Copy Destination:=new_xls.Cells(better, 1)
If qb_list = "" Then
qb_list = qb_list & Mid(qb.Value, 1, Len(qb.Value) - 7) &
vbCrLf
Else
qb_list = qb_list & " &" & Mid(qb.Value, 1, Len(qb.Value) -
7) & vbCrLf
End If

Else
worse = worse + 1#
End If
Next qb

--
HTH...

Jim Thomlinson


"David Gerstman" wrote:

I want to save rows that match a certain criteria to a new worksheet. When I
complete the task, I want to save that worksheet to a file.

I create the worksheet like this:

Set new_xls = Worksheets.Add
new_xls.Move after:=Worksheets(Worksheets.Count)

The move is to put it at the end of the workbook, though I suppose I could
have done it in a single line of code when I created it.

The problem I have is that when I select the data and copy it only works the
first time through the loop. I get an appication error the second time I
paste. (The first time things seem to work properly.

For Each qb In qb_range
If qb.Offset(0, 13) rav_rat Then

better = better + 1#
qb.EntireRow.Copy
ActiveSheet.Paste Destination:=new_xls.Cells(1, Int(better))
If qb_list = "" Then
qb_list = qb_list & Mid(qb.Value, 1, Len(qb.Value) - 7) &
vbCrLf
Else
qb_list = qb_list & " &" & Mid(qb.Value, 1, Len(qb.Value) -
7) & vbCrLf
End If

Else
worse = worse + 1#
End If
Next qb

What am I doing wrong?

Thanks,
David


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
Is it possible to copy only selected items to another worksheet... HEATHERCOX Excel Worksheet Functions 2 March 1st 05 01:21 PM
copy selected rows to new sheet Bryan[_13_] Excel Programming 2 March 1st 05 04:17 AM
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 10:09 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"