Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Create sheet with records for each rep in filtered list

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Create sheet with records for each rep in filtered list

Aline,

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

HTH,
Bernie
MS Excel MVP


"Aline" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Create sheet with records for each rep in filtered list

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Create sheet with records for each rep in filtered list

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" wrote in message
...
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
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
select random sample of records in a filtered list David3553 Excel Discussion (Misc queries) 2 November 25th 09 11:37 PM
Count Unique Records in Filtered List ryguy7272 Excel Programming 2 November 17th 08 07:08 PM
Code to create a list of records in another sheet, based on the entryof the word "Terminated" in a given column Mike C[_5_] Excel Programming 0 May 15th 08 12:49 AM
Create new excel table with filtered records from another table Berne van de Laar Excel Worksheet Functions 3 July 3rd 06 12:14 AM
Counting records in a filtered list plato Excel Programming 2 August 5th 04 12:50 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"