Copy sets of 200 records for each unique item in an autofilter to new worksheets

cmadsen

New Member
Joined
Sep 3, 2013
Messages
2
Hello all,
Just cutting my teeth on VBA and have a question. I have a spreadsheet that I am filtering on a specific column. I have been able to create new worksheets containing the records matching each unique value in the autofilter. What I really want to do is create worksheets with groups of 200 records within each unique value. The unique values that do not have 200 records should just have the numbers of records in their set.

Here is what I have so far. It works great to create the separate sheets for each unique value, but I want to have them broken out in groups of 200:

'Create new sheets based on filter of Specialty Code column
Dim c As Range
Dim rng As Range
Dim LR As Long

'Last Row
LR = Cells(Rows.Count, "A").End(xlUp).Row
'Range of Data
Set rng = Range("A1:N" & LR)

'populate trailing column with unique values in column K. Used to loop through and create worksheets below
Range("K2:K" & LR).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("O1"), Unique:=True

For Each c In Range([O2], Cells(Rows.Count, "O").End(xlUp))
With rng
.AutoFilter
.AutoFilter Field:=11, Criteria1:=c.Value
.SpecialCells(xlCellTypeVisible).Copy
Sheets.Add(After:=Sheets(Sheets.Count)).Name = c.Value
ActiveSheet.Paste
Cells.Select
Cells.EntireColumn.autofit


End With
Next c

Appreciate the help!!!

Chad
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,215,001
Messages
6,122,648
Members
449,092
Latest member
peppernaut

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