coping all rows between two rows

cirugio

Board Regular
Joined
Mar 30, 2010
Messages
130
I need to copy all rows between the words “Report 1” and “Column Totals” into cell A1 of a new workbook worksheet. I am not exactly certain how to go about this. Hoping someone can help. I am at a total loss.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
Example of Report:
<o:p></o:p>
Report 1
-
-
-
-
-
-
-
-
-
Column Totals:
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I would use a macro like this one:
Sub Macro1()
Columns("A:A").Select 'Select column to search for the key words
Selection.Find(What:="Report 1", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate 'search for "Report 1"
Rng1 = ActiveCell.Row 'Beginning range
Selection.Find(What:="Column Totals", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate 'search for "Column Totals"
Rng2 = ActiveCell.Row 'Ending range
Rows(Rng1 & ":" & Rng2).Select 'Select rows to be copied
Selection.Copy
Workbooks.Add 'Open a new workbook
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A1").Select
End Sub
 
Upvote 0
Thanks for the reply. That worked out great. :)

Wondering if you can answer another question pertaining to the code.

I actually need to Paste only the values and not the formulas in my copy. I tried replacing your "ActiveSheet.Paste" logic with

ActiveSheet.PasteSpecial Paste:=xlValues ', Operation:=xlNone, SkipBlanks:=False, Transpose:=False

but it fails on me. Is there a why to only copy and paste the special values?
 
Upvote 0
Try like this maybe

Code:
Sub Macro1()
Dim stRange As Long
Dim enRange As Long
With Columns("A:A")
    stRange = .Find(What:="Report 1", After:=Range("A1")).Row 'Beginning range
    enRange = .Find(What:="Column Totals", After:=Range("A1")).Row 'search for "Column Totals"
End With
Rows(stRange & ":" & enRange).Copy
Workbooks.Add 'Open a new workbook
Range("A1").PasteSpecial xlPasteValues
Application.CutCopyMode = False
End Sub
 
Upvote 0
Thanks Dave. That worked out well.
I had to expand the logic (see below) so that it will then delete rows which contain certain values within column A (i.e. "testing", "Client A", "Client B", and blanks).

The logic works, but it only deletes the blank rows, and totally ignores the others. Would you know what it is doing this?

With ActiveSheet
.AutoFilterMode = False
With Range("A6:A" & enRange)
.AutoFilter 1, Criteria1:=Array("testing", "Client A", "Client B", "=")
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,749
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top