PC Review


Reply
Thread Tools Rate Thread

how to consolidate two ranges in a new workbook

 
 
Dave F
Guest
Posts: n/a
 
      19th Jun 2007
I have a report downloaded from a server, spread over two sheets,
Sheet1 and Sheet2 (the data runs to about 100,000 rows; I'm using XL
2003)

I want to run Advanced filter on both sheets and copy the filtered
records on both sheets and paste them into a new workbook.

Both sheets contain the same number of columns but a different number
of rows.

I've figured out how to do everything *except* how to copy and paste
the two separate ranges into one consolidated range in the new
workbook. So, following is the code I have:

Option Explicit
Sub FilterFAS()
Dim myFileName As String, myRow As Long, myRow2 As Long, myRow3 As
Long
Dim myRow4 As Long, myRow5 As Long, myRow6 As Long

If ActiveSheet.AutoFilterMode = True Then
ActiveSheet.ShowAllData
End If

myRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
myRow2 = Sheet1.Cells(Rows.Count, 40).End(xlUp).Row
myRow3 = Sheet1.Cells(Rows.Count, 42).End(xlUp).Row
myRow4 = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row
myRow5 = Sheet2.Cells(Rows.Count, 40).End(xlUp).Row
myRow6 = Sheet2.Cells(Rows.Count, 42).End(xlUp).Row
Sheet1.Range("A1:AL" & myRow).AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Sheet1.Range("AN1:AN" & myRow2),
CopyToRange:=Sheet1.Range("AP1"), Unique:=False
Sheet2.Range("A1:AL" & myRow4).AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Sheet2.Range("AN1:AN" & myRow5),
CopyToRange:=Sheet2.Range("AP1"), Unique:=False
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
myFileName = Application.GetSaveAsFilename
If myFileName = False Then
Exit Sub
End If
ActiveWorkbook.SaveAs Filename:=myFileName,
FileFormat:=xlWorkbookNormal
End Sub

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      19th Jun 2007
Option Explicit
Sub FilterFAS()
Dim myFileName As String, myRow As Long, _
myRow2 As Long, myRow3 As Long
Dim myRow4 As Long, myRow5 As Long, myRow6 As Long
Dim bk as Workbook, sh as Worksheet, rng as Range
Dim sh1 as Worksheet
set sh1 = ActiveSheet
set bk = Workbooks.Add(Template:=xlWBATWorksheet)
set sh = bk.worksheets(1)
set rng = sh.Range("A1")
Application.CutCopyMode = False
myFileName = Application.GetSaveAsFilename
If myFileName = False Then
Exit Sub
End If
bk.SaveAs Filename:=myFileName, _
FileFormat:=xlWorkbookNormal
Application.Goto sh1.Range("A1"), True

If ActiveSheet.AutoFilterMode = True Then
ActiveSheet.ShowAllData
End If

myRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
myRow2 = Sheet1.Cells(Rows.Count, 40).End(xlUp).Row
myRow3 = Sheet1.Cells(Rows.Count, 42).End(xlUp).Row
myRow4 = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row
myRow5 = Sheet2.Cells(Rows.Count, 40).End(xlUp).Row
myRow6 = Sheet2.Cells(Rows.Count, 42).End(xlUp).Row
Sheet1.Range("A1:AL" & myRow).AdvancedFilter _
Action:=xlFilterCopy, _
CriteriaRange:=Sheet1.Range("AN1:AN" & myRow2), _
CopyToRange:=rng, _
Unique = False

set rng = sh.Cells(rows.count,1).end(xlup)(3)

Sheet2.Range("A1:AL" & myRow4).AdvancedFilter _
Action:=xlFilterCopy, _
CriteriaRange:=Sheet2.Range("AN1:AN" & myRow5), _
CopyToRange:=rng, _
Unique:=False
bk.Save
End Sub

--
Regards,
Tom Ogilvy

"Dave F" wrote:

> I have a report downloaded from a server, spread over two sheets,
> Sheet1 and Sheet2 (the data runs to about 100,000 rows; I'm using XL
> 2003)
>
> I want to run Advanced filter on both sheets and copy the filtered
> records on both sheets and paste them into a new workbook.
>
> Both sheets contain the same number of columns but a different number
> of rows.
>
> I've figured out how to do everything *except* how to copy and paste
> the two separate ranges into one consolidated range in the new
> workbook. So, following is the code I have:
>
> Option Explicit
> Sub FilterFAS()
> Dim myFileName As String, myRow As Long, myRow2 As Long, myRow3 As
> Long
> Dim myRow4 As Long, myRow5 As Long, myRow6 As Long
>
> If ActiveSheet.AutoFilterMode = True Then
> ActiveSheet.ShowAllData
> End If
>
> myRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
> myRow2 = Sheet1.Cells(Rows.Count, 40).End(xlUp).Row
> myRow3 = Sheet1.Cells(Rows.Count, 42).End(xlUp).Row
> myRow4 = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row
> myRow5 = Sheet2.Cells(Rows.Count, 40).End(xlUp).Row
> myRow6 = Sheet2.Cells(Rows.Count, 42).End(xlUp).Row
> Sheet1.Range("A1:AL" & myRow).AdvancedFilter Action:=xlFilterCopy,
> CriteriaRange:=Sheet1.Range("AN1:AN" & myRow2),
> CopyToRange:=Sheet1.Range("AP1"), Unique:=False
> Sheet2.Range("A1:AL" & myRow4).AdvancedFilter Action:=xlFilterCopy,
> CriteriaRange:=Sheet2.Range("AN1:AN" & myRow5),
> CopyToRange:=Sheet2.Range("AP1"), Unique:=False
> Workbooks.Add
> ActiveSheet.Paste
> Application.CutCopyMode = False
> myFileName = Application.GetSaveAsFilename
> If myFileName = False Then
> Exit Sub
> End If
> ActiveWorkbook.SaveAs Filename:=myFileName,
> FileFormat:=xlWorkbookNormal
> End Sub
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I consolidate data into ranges Jerry Microsoft Excel Misc 8 15th Jul 2008 09:09 PM
consolidate data, dynamic ranges =?Utf-8?B?RXhjZWwgR3VSdQ==?= Microsoft Excel Programming 1 28th Feb 2006 01:48 PM
Need to consolidate multiple ranges =?Utf-8?B?RXhjZWwgR3VSdQ==?= Microsoft Excel Programming 2 28th Feb 2006 01:11 PM
Consolidate Ranges into 1 Workbook John Microsoft Excel Programming 15 19th Dec 2005 03:12 PM
Re: Using pivot tables to consolidate data ranges Debra Dalgleish Microsoft Excel Misc 0 15th Sep 2003 07:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:37 AM.