PC Review


Reply
Thread Tools Rate Thread

Creating sheet and copying filtered rows in it

 
 
shabutt
Guest
Posts: n/a
 
      17th Dec 2008
Hi to everyone,

The copyfilter code (copies the filtered rows from the active sheet to
another sheet) works perfectly for my data. But I would like to modify one
thing in it but could not do it with my limited vba knowledge and would like
your help.

This code doesn't create sheet(s) automatically for filtered criteria. But I
want the code to create the sheet(s) as per filter criteria(s) and copy the
filtered rows in it.

Here is the code from www.contextures.com/xlautofilter03.html

Sub CopyFilter()
'by Tom Ogilvy
Dim rng As Range
Dim rng2 As Range

With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If rng2 Is Nothing Then
MsgBox "No data to copy"
Else
Worksheets("Sheet2").Cells.Clear
Set rng = ActiveSheet.AutoFilter.Range
rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
Destination:=Worksheets("Sheet2").Range("A1")
End If
ActiveSheet.ShowAllData
End Sub

Please guide me.

Regrads
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      17th Dec 2008
Sub CopyFilter()
'by Tom Ogilvy
Dim rng As Range
Dim rng2 As Range

Set OldSht = ActiveSheet
With OldSht.AutoFilter.Range
On Error Resume Next
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
FilterValue = rng2(0)
On Error GoTo 0


End With
If rng2 Is Nothing Then
MsgBox "No data to copy"
Else
Sheets.Add after:=Sheets(Sheets.Count)
Set NewSht = ActiveSheet
NewSht.Name = FilterValue
Set rng = OldSht.AutoFilter.Range
rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
Destination:=NewSht.Range("A1")
End If
OldSht.ShowAllData
End Sub

"shabutt" wrote:

> Hi to everyone,
>
> The copyfilter code (copies the filtered rows from the active sheet to
> another sheet) works perfectly for my data. But I would like to modify one
> thing in it but could not do it with my limited vba knowledge and would like
> your help.
>
> This code doesn't create sheet(s) automatically for filtered criteria. But I
> want the code to create the sheet(s) as per filter criteria(s) and copy the
> filtered rows in it.
>
> Here is the code from www.contextures.com/xlautofilter03.html
>
> Sub CopyFilter()
> 'by Tom Ogilvy
> Dim rng As Range
> Dim rng2 As Range
>
> With ActiveSheet.AutoFilter.Range
> On Error Resume Next
> Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
> .SpecialCells(xlCellTypeVisible)
> On Error GoTo 0
> End With
> If rng2 Is Nothing Then
> MsgBox "No data to copy"
> Else
> Worksheets("Sheet2").Cells.Clear
> Set rng = ActiveSheet.AutoFilter.Range
> rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
> Destination:=Worksheets("Sheet2").Range("A1")
> End If
> ActiveSheet.ShowAllData
> End Sub
>
> Please guide me.
>
> Regrads

 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      17th Dec 2008
hi shabutt

See
http://www.rondebruin.nl/copy5.htm


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"shabutt" <(E-Mail Removed)> wrote in message news:C23273F3-72E2-480E-BE77-(E-Mail Removed)...
> Hi to everyone,
>
> The copyfilter code (copies the filtered rows from the active sheet to
> another sheet) works perfectly for my data. But I would like to modify one
> thing in it but could not do it with my limited vba knowledge and would like
> your help.
>
> This code doesn't create sheet(s) automatically for filtered criteria. But I
> want the code to create the sheet(s) as per filter criteria(s) and copy the
> filtered rows in it.
>
> Here is the code from www.contextures.com/xlautofilter03.html
>
> Sub CopyFilter()
> 'by Tom Ogilvy
> Dim rng As Range
> Dim rng2 As Range
>
> With ActiveSheet.AutoFilter.Range
> On Error Resume Next
> Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
> .SpecialCells(xlCellTypeVisible)
> On Error GoTo 0
> End With
> If rng2 Is Nothing Then
> MsgBox "No data to copy"
> Else
> Worksheets("Sheet2").Cells.Clear
> Set rng = ActiveSheet.AutoFilter.Range
> rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
> Destination:=Worksheets("Sheet2").Range("A1")
> End If
> ActiveSheet.ShowAllData
> End Sub
>
> Please guide me.
>
> Regrads

 
Reply With Quote
 
shabutt
Guest
Posts: n/a
 
      18th Dec 2008
Hi Joel,

Thank you for your time and help. Your code misses a few points I mentioned
in my earlier post.

1- I want separate sheet(s) for each filter value, i.e., one sheet for one
filter value, two sheets for two filter values and so on.

2- The sheet(s) should be named on filter value(s).

Another request for you: How could the first row (column labels) be copied
with the filtered data.

Regards.


"Joel" wrote:

> Sub CopyFilter()
> 'by Tom Ogilvy
> Dim rng As Range
> Dim rng2 As Range
>
> Set OldSht = ActiveSheet
> With OldSht.AutoFilter.Range
> On Error Resume Next
> Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
> .SpecialCells(xlCellTypeVisible)
> FilterValue = rng2(0)
> On Error GoTo 0
>
>
> End With
> If rng2 Is Nothing Then
> MsgBox "No data to copy"
> Else
> Sheets.Add after:=Sheets(Sheets.Count)
> Set NewSht = ActiveSheet
> NewSht.Name = FilterValue
> Set rng = OldSht.AutoFilter.Range
> rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
> Destination:=NewSht.Range("A1")
> End If
> OldSht.ShowAllData
> End Sub
>
> "shabutt" wrote:
>
> > Hi to everyone,
> >
> > The copyfilter code (copies the filtered rows from the active sheet to
> > another sheet) works perfectly for my data. But I would like to modify one
> > thing in it but could not do it with my limited vba knowledge and would like
> > your help.
> >
> > This code doesn't create sheet(s) automatically for filtered criteria. But I
> > want the code to create the sheet(s) as per filter criteria(s) and copy the
> > filtered rows in it.
> >
> > Here is the code from www.contextures.com/xlautofilter03.html
> >
> > Sub CopyFilter()
> > 'by Tom Ogilvy
> > Dim rng As Range
> > Dim rng2 As Range
> >
> > With ActiveSheet.AutoFilter.Range
> > On Error Resume Next
> > Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
> > .SpecialCells(xlCellTypeVisible)
> > On Error GoTo 0
> > End With
> > If rng2 Is Nothing Then
> > MsgBox "No data to copy"
> > Else
> > Worksheets("Sheet2").Cells.Clear
> > Set rng = ActiveSheet.AutoFilter.Range
> > rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _
> > Destination:=Worksheets("Sheet2").Range("A1")
> > End If
> > ActiveSheet.ShowAllData
> > End Sub
> >
> > Please guide me.
> >
> > Regrads

 
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
Copying into Filtered rows Snara Microsoft Excel Discussion 3 15th May 2009 03:33 PM
Cut filtered rows, paste into next empty row of new sheet, and delete cut rows Scott Microsoft Excel Worksheet Functions 0 13th Dec 2006 01:25 AM
Copying the filtered data to clipboard is copying non-visible rows =?Utf-8?B?U2VldGhhUmFtYW4=?= Microsoft Excel Crashes 10 12th Jul 2006 09:39 PM
Re: Copying JUST the filtered rows David Biddulph Microsoft Excel Misc 0 21st Jul 2004 06:11 PM
Re: Copying JUST the filtered rows Bernie Deitrick Microsoft Excel Misc 0 21st Jul 2004 05:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:38 PM.