Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Kim Kim is offline
external usenet poster
 
Posts: 284
Default copy specific rows to a new sheet

Hi
I have several rows of information in a worksheet I need a macro or code to
select only the rows that do not have the word "keep" anywhere in them, copy
those rows and open a new workbook and paste them into the worksheet then
save the worksheet in my documents with month as the filename.
I manage to do this with a macro selecting specific rows by drag and select
but the layout changes so this no good.
Help appreciated
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default copy specific rows to a new sheet

Hi Kim,

'-------------------
I have several rows of information in a worksheet I need a macro or code to
select only the rows that do not have the word "keep" anywhere in them,
copy
those rows and open a new workbook and paste them into the worksheet then
save the worksheet in my documents with month as the filename.
I manage to do this with a macro selecting specific rows by drag and select
but the layout changes so this no good.
'-------------------

Try something like;

'================
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim destSH As Worksheet
Dim rng As Range
Dim rCell As Range
Dim Rng2 As Range
Dim iRow As Long
Dim CalcMode As Long
Const sStr As String = "keep" '<<===== CHANGE

Set WB = Workbooks("MyBook.xls") '<<===== CHANGE
Set SH = WB.Sheets("Sheet1") '<<===== CHANGE

With SH
iRow = .Cells(Rows.Count, "A").End(xlUp).Row
Set rng = SH.Range("A1:A" & iRow)
End With

On Error GoTo XIT
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With


For Each rCell In rng.Cells
If Application.CountIf( _
rCell.EntireRow, "*" & sStr & "*") Then
If Rng2 Is Nothing Then
Set Rng2 = rCell
Else
Set Rng2 = Union(rCell, Rng2)
End If
End If
Next rCell

If Not Rng2 Is Nothing Then
With WB
Set destSH = .Worksheets.Add( _
After:=.Sheets(.Sheets.Count))
End With

With destSH
Rng2.Copy Destination:=destSH.Range("A1")
.Name = Format(Date, "mmmm")
.Copy
End With

With ActiveWorkbook
.SaveAs Filename:=destSH.Name & ".xls"
.Close SaveChanges:=False
End With
End If

XIT:
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With
End Sub
'<<================


---
Regards,
Norman


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default copy specific rows to a new sheet

Hi Kim,


Re-reading your post, replace:

If Application.CountIf( _
rCell.EntireRow, "*" & sStr & "*") Then



with

If Application.CountIf( _
rCell.EntireRow, "*" & sStr & "*") = 0 Then


---
Regards,
Norman


  #4   Report Post  
Posted to microsoft.public.excel.programming
Kim Kim is offline
external usenet poster
 
Posts: 284
Default copy specific rows to a new sheet

Thanks Norman it produced the workbook but no data pasted. I moved my data to
cell A1 tried again . It did paste only the rows but only the data in column
A how can get to paste data from the other columns?
I tried to figure this out by looking a t the code but can't get there!
Thanks

"Norman Jones" wrote:

Hi Kim,


Re-reading your post, replace:

If Application.CountIf( _
rCell.EntireRow, "*" & sStr & "*") Then



with

If Application.CountIf( _
rCell.EntireRow, "*" & sStr & "*") = 0 Then


---
Regards,
Norman



  #5   Report Post  
Posted to microsoft.public.excel.programming
Kim Kim is offline
external usenet poster
 
Posts: 284
Default copy specific rows to a new sheet

Hi Norman
I chaged the range in the code from A1:A to A1:Z400
This caught the data was this the correct approach?
Thanks

"kim" wrote:

Thanks Norman it produced the workbook but no data pasted. I moved my data to
cell A1 tried again . It did paste only the rows but only the data in column
A how can get to paste data from the other columns?
I tried to figure this out by looking a t the code but can't get there!
Thanks

"Norman Jones" wrote:

Hi Kim,


Re-reading your post, replace:

If Application.CountIf( _
rCell.EntireRow, "*" & sStr & "*") Then



with

If Application.CountIf( _
rCell.EntireRow, "*" & sStr & "*") = 0 Then


---
Regards,
Norman





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default copy specific rows to a new sheet

Hi Kim,

'----------------
I chaged the range in the code from A1:A to A1:Z400
This caught the data was this the correct approach?
'----------------

See my response to your previous post..

However, it should be necessary only to replace 'A'
with a column that defines the last data row.

To copy the entire data rows, adopt also my second
suggestion.


---
Regards,
Norman


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default copy specific rows to a new sheet

Hi Kim,

'------------------
Thanks Norman it produced the workbook but no data pasted. I moved my data
to
cell A1 tried again . It did paste only the rows but only the data in column
A how can get to paste data from the other columns?
I tried to figure this out by looking a t the code but can't get there!
'------------------

(1) Change:

Set rng = SH.Range("A1:A" & iRow)


to reflect a column which encompasses all of your data.


(2) Change

Rng2.Copy Destination:=destSH.Range("A1")


to:

Rng2EntireRow.Copy Destination:=destSH.Range("A1")


---
Regards,
Norman


  #8   Report Post  
Posted to microsoft.public.excel.programming
Kim Kim is offline
external usenet poster
 
Posts: 284
Default copy specific rows to a new sheet

Hi Norman
Looking at this, away from the code ,for what I need to record it makes more
sense to have the code copy the rows where the word "Keep" does not appear is
it possible to change the code to do this?
Thanks for your help

"Norman Jones" wrote:

Hi Kim,

'------------------
Thanks Norman it produced the workbook but no data pasted. I moved my data
to
cell A1 tried again . It did paste only the rows but only the data in column
A how can get to paste data from the other columns?
I tried to figure this out by looking a t the code but can't get there!
'------------------

(1) Change:

Set rng = SH.Range("A1:A" & iRow)


to reflect a column which encompasses all of your data.


(2) Change

Rng2.Copy Destination:=destSH.Range("A1")


to:

Rng2EntireRow.Copy Destination:=destSH.Range("A1")


---
Regards,
Norman



  #9   Report Post  
Posted to microsoft.public.excel.programming
Kim Kim is offline
external usenet poster
 
Posts: 284
Default copy specific rows to a new sheet

Thanks Norman that last code seems to have worked and done the job. One more
thing it puts the copied information in a new workbook is it possible to put
some code in there t0 save the workbook in my documents?
Thanks

"Norman Jones" wrote:

Hi Kim,

'------------------
Thanks Norman it produced the workbook but no data pasted. I moved my data
to
cell A1 tried again . It did paste only the rows but only the data in column
A how can get to paste data from the other columns?
I tried to figure this out by looking a t the code but can't get there!
'------------------

(1) Change:

Set rng = SH.Range("A1:A" & iRow)


to reflect a column which encompasses all of your data.


(2) Change

Rng2.Copy Destination:=destSH.Range("A1")


to:

Rng2EntireRow.Copy Destination:=destSH.Range("A1")


---
Regards,
Norman



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 rows to new sheet based on specific cell value dlballard Excel Worksheet Functions 5 April 24th 23 11:44 AM
Copy / paste only specific rows Benjamin Excel Discussion (Misc queries) 3 April 11th 08 03:14 PM
copy specific rows using "IF" to another sheet Henry Excel Worksheet Functions 3 December 24th 07 03:41 AM
COPY AND PASTE SPECIFIC ROWS HERNAN Excel Discussion (Misc queries) 2 August 17th 06 07:32 PM
Copy rows with a specific value in column A Gert-Jan Excel Programming 7 June 23rd 06 05:13 PM


All times are GMT +1. The time now is 11:25 PM.

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"