PC Review


Reply
Thread Tools Rate Thread

Create sheet with records for each rep in filtered list

 
 
Aline
Guest
Posts: n/a
 
      16th Dec 2008
I have obtained a macro (AdvFilterRepFitered) that can create sheets with
records for each rep in filtered list (if a sheet already exists for a rep,
it will be cleared, and the data will be extracted to that sheet). It will
create sheets with rep's name.

How could modify it so the names for the created sheets will be C1, C2, C3,
C4 (not rep's name)...(depending on how many reps we have)

Any help will be appreciated.
--
Aline
 
Reply With Quote
 
 
 
 
Bernie Deitrick
Guest
Posts: n/a
 
      16th Dec 2008
Aline,

It would be best if you posted the code that you want modified.

HTH,
Bernie
MS Excel MVP


"Aline" <(E-Mail Removed)> wrote in message
news:AA92E9DC-C476-491D-B565-(E-Mail Removed)...
>I have obtained a macro (AdvFilterRepFitered) that can create sheets with
> records for each rep in filtered list (if a sheet already exists for a rep,
> it will be cleared, and the data will be extracted to that sheet). It will
> create sheets with rep's name.
>
> How could modify it so the names for the created sheets will be C1, C2, C3,
> C4 (not rep's name)...(depending on how many reps we have)
>
> Any help will be appreciated.
> --
> Aline



 
Reply With Quote
 
Aline
Guest
Posts: n/a
 
      16th Dec 2008
Here is the codes:

***
Sub ExtractReps()
Dim ws1 As Worksheet
Dim wsNew As Worksheet
Dim rng As Range
Dim r As Integer
Dim c As Range
Set ws1 = Sheets("Sheet1")
Set rng = Range("Database")

'extract a list of Sales Reps
ws1.Columns("C:C").Copy _
Destination:=Range("L1")
ws1.Columns("L:L").AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=Range("J1"), Unique:=True
r = Cells(Rows.Count, "J").End(xlUp).Row

'set up Criteria Area
Range("L1").Value = Range("C1").Value

For Each c In Range("J2:J" & r)
'add the rep name to the criteria area
ws1.Range("L2").Value = c.Value
'add new sheet (if required)
'and run advanced filter
If WksExists(c.Value) Then
Sheets(c.Value).Cells.Clear
rng.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheets("Sheet1").Range("L1:L2"), _
CopyToRange:=Sheets(c.Value).Range("A1"), _
Unique:=False
Else
Set wsNew = Sheets.Add
wsNew.Move After:=Worksheets(Worksheets.Count)
wsNew.Name = c.Value
rng.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheets("Sheet1").Range("L1:L2"), _
CopyToRange:=wsNew.Range("A1"), _
Unique:=False
End If
Next
ws1.Select
ws1.Columns("J:L").Delete
End Sub
Function WksExists(wksName As String) As Boolean
On Error Resume Next
WksExists = CBool(Len(Worksheets(wksName).Name) > 0)
End Function

***

Thanks,
Aline



--
Aline


"Aline" wrote:

> I have obtained a macro (AdvFilterRepFitered) that can create sheets with
> records for each rep in filtered list (if a sheet already exists for a rep,
> it will be cleared, and the data will be extracted to that sheet). It will
> create sheets with rep's name.
>
> How could modify it so the names for the created sheets will be C1, C2, C3,
> C4 (not rep's name)...(depending on how many reps we have)
>
> Any help will be appreciated.
> --
> Aline

 
Reply With Quote
 
Bernie Deitrick
Guest
Posts: n/a
 
      16th Dec 2008
Try this version:


HTH,
Bernie
MS Excel MVP

Sub ExtractReps()
Dim ws1 As Worksheet
Dim wsNew As Worksheet
Dim rng As Range
Dim r As Integer
Dim c As Range
Dim myC As Integer

Set ws1 = Sheets("Sheet1")
Set rng = Range("Database")
myC = 0

'extract a list of Sales Reps
ws1.Columns("C:C").Copy _
Destination:=Range("L1")
ws1.Columns("L:L").AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=Range("J1"), Unique:=True
r = Cells(Rows.Count, "J").End(xlUp).Row

'set up Criteria Area
Range("L1").Value = Range("C1").Value

For Each c In Range("J2:J" & r)
'add the rep name to the criteria area
ws1.Range("L2").Value = c.Value
'add new sheet (if required)
'and run advanced filter
If WksExists(c.Value) Then
Sheets(c.Value).Cells.Clear
rng.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheets("Sheet1").Range("L1:L2"), _
CopyToRange:=Sheets(c.Value).Range("A1"), _
Unique:=False
Else
Set wsNew = Sheets.Add
wsNew.Move After:=Worksheets(Worksheets.Count)
myC = myC + 1
wsNew.Name = "C" & myC
rng.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheets("Sheet1").Range("L1:L2"), _
CopyToRange:=wsNew.Range("A1"), _
Unique:=False
End If
Next
ws1.Select
ws1.Columns("J:L").Delete
End Sub

Function WksExists(wksName As String) As Boolean
On Error Resume Next
WksExists = CBool(Len(Worksheets(wksName).Name) > 0)
End Function






"Aline" <(E-Mail Removed)> wrote in message
newsA9209D7-D2CB-490B-98F4-(E-Mail Removed)...
> Here is the codes:
>
> ***
> Sub ExtractReps()
> Dim ws1 As Worksheet
> Dim wsNew As Worksheet
> Dim rng As Range
> Dim r As Integer
> Dim c As Range
> Set ws1 = Sheets("Sheet1")
> Set rng = Range("Database")
>
> 'extract a list of Sales Reps
> ws1.Columns("C:C").Copy _
> Destination:=Range("L1")
> ws1.Columns("L:L").AdvancedFilter _
> Action:=xlFilterCopy, _
> CopyToRange:=Range("J1"), Unique:=True
> r = Cells(Rows.Count, "J").End(xlUp).Row
>
> 'set up Criteria Area
> Range("L1").Value = Range("C1").Value
>
> For Each c In Range("J2:J" & r)
> 'add the rep name to the criteria area
> ws1.Range("L2").Value = c.Value
> 'add new sheet (if required)
> 'and run advanced filter
> If WksExists(c.Value) Then
> Sheets(c.Value).Cells.Clear
> rng.AdvancedFilter Action:=xlFilterCopy, _
> CriteriaRange:=Sheets("Sheet1").Range("L1:L2"), _
> CopyToRange:=Sheets(c.Value).Range("A1"), _
> Unique:=False
> Else
> Set wsNew = Sheets.Add
> wsNew.Move After:=Worksheets(Worksheets.Count)
> wsNew.Name = c.Value
> rng.AdvancedFilter Action:=xlFilterCopy, _
> CriteriaRange:=Sheets("Sheet1").Range("L1:L2"), _
> CopyToRange:=wsNew.Range("A1"), _
> Unique:=False
> End If
> Next
> ws1.Select
> ws1.Columns("J:L").Delete
> End Sub
> Function WksExists(wksName As String) As Boolean
> On Error Resume Next
> WksExists = CBool(Len(Worksheets(wksName).Name) > 0)
> End Function
>
> ***
>
> Thanks,
> Aline
>
>
>
> --
> Aline
>
>
> "Aline" wrote:
>
>> I have obtained a macro (AdvFilterRepFitered) that can create sheets with
>> records for each rep in filtered list (if a sheet already exists for a rep,
>> it will be cleared, and the data will be extracted to that sheet). It will
>> create sheets with rep's name.
>>
>> How could modify it so the names for the created sheets will be C1, C2, C3,
>> C4 (not rep's name)...(depending on how many reps we have)
>>
>> Any help will be appreciated.
>> --
>> Aline



 
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
Copy Paste from Class Sheet to Filtered List on Combined Sheet prkhan56@gmail.com Microsoft Excel Programming 6 16th Sep 2008 04:30 PM
Code to create a list of records in another sheet, based on the entryof the word "Terminated" in a given column Mike C Microsoft Excel Programming 1 15th May 2008 01:43 AM
how to make a filtered list on a different sheet =?Utf-8?B?TWFkZHVjaw==?= Microsoft Excel Misc 4 22nd Aug 2007 11:42 AM
Create table from Filtered records on a form =?Utf-8?B?aHVnaGVzczc=?= Microsoft Access 1 13th Mar 2007 09:35 PM
Counting records in a filtered list plato Microsoft Excel Programming 2 5th Aug 2004 12:50 PM


Features
 

Advertising
 

Newsgroups
 


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