Add code to my current split macro to pull in first 25 rows

ninjabik2001

New Member
Joined
Jun 27, 2019
Messages
3
Hello,

I have a macro that splits one workbook into multiple based on column A (The provider). I want only the first 25 rows or less of that provider and some have less than 25 and others have over 200. I tried a count and still can't figure out the exact code. Im a newby somewhat to VBA so please bear w me. This is my spilt macro code. Any help would be appreciated. Thanks

Sub RosterSplit()
'This version copies entire sheet and then removes unwanted rows


Application.ScreenUpdating = False
Application.DisplayAlerts = False


iCol = 1 '### Define your criteria column
strOutputFolder = "S:\dept\PCP Quality\2019\Mike Split Folder"
Set ws = ThisWorkbook.ActiveSheet
Set rngLast = Columns(iCol).Find("*", Cells(1, iCol), , , xlByColumns, xlPrevious)
ws.Columns(iCol).AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Set rngUnique = Range(Cells(2, iCol), rngLast).SpecialCells(xlCellTypeVisible)




If Dir(strOutputFolder, vbDirectory) = vbNullString Then MkDir strOutputFolder
For Each strItem In rngUnique
If strItem <> "" Then

ws.Copy

'If TypeName(ActiveSheet.AutoFilter) = "AutoFilter" Or ActiveSheet.AutoFilterMode Then
ActiveSheet.Range("A1").AutoFilter 'Turn off AutoFilter
'End If

ActiveSheet.Cells.ClearContents
ActiveSheet.Rows.Hidden = False


ws.UsedRange.AutoFilter Field:=iCol, Criteria1:=strItem.Value
ws.UsedRange.SpecialCells(xlCellTypeVisible).Copy Destination:=ActiveSheet.Range("a1")

ActiveSheet.PageSetup.PrintArea = "$a1:$K$" & Cells(Rows.Count, "A").End(xlUp).Row '# Make sure to change to last column
'ActiveSheet.Range("A2").Activate
ActiveSheet.Range("A2").Select
ActiveWindow.LargeScroll down:=-1
strfilename = strOutputFolder & "" & strItem
ActiveWorkbook.SaveAs Filename:=strfilename, FileFormat:=51
ActiveWorkbook.Close savechanges:=False
End If
Next
ws.ShowAllData


Application.ScreenUpdating = True
Application.DisplayAlerts = True


End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try adding this line
Code:
Ws.UsedRange.SpecialCells(xlCellTypeVisible).Copy Destination:=ActiveSheet.Range("a1")
[COLOR=#0000ff]ActiveSheet.Rows("27:" & Rows.Count).Delete[/COLOR]
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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