MaizeandBlue
New Member
- Joined
- Mar 2, 2020
- Messages
- 2
- Office Version
- 2019
- 2016
- 2013
- Platform
- Windows
Hello,
I have read through multiple VBA codes for splitting out row data on a worksheet. What I am specifically trying to do is as follows:
Split out data for every 15 rows of information into their own worksheets.
I want to keep Row and Column widths based on the master sheet.
The master sheet has the first row as a header, and I would like to have that header copy to each sheet.
I found the below code, that split out the rows correctly, but I could not get widths or the header to carry over. All help is greatly greatly greatly appreciated.
Sub SplitData()
'Updateby20140617
Dim WorkRng As Range
Dim xRow As Range
Dim SplitRow As Integer
Dim xWs As Worksheet
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
SplitRow = Application.InputBox("Split Row Num", xTitleId, 5, Type:=1)
Set xWs = WorkRng.Parent
Set xRow = WorkRng.Rows(1)
Application.ScreenUpdating = False
For i = 1 To WorkRng.Rows.Count Step SplitRow
resizeCount = SplitRow
If (WorkRng.Rows.Count - xRow.Row + 1) < SplitRow Then resizeCount = WorkRng.Rows.Count - xRow.Row + 1
xRow.Resize(resizeCount).Copy
Application.Worksheets.Add after:=Application.Worksheets(Application.Worksheets.Count)
Application.ActiveSheet.Range("A1").PasteSpecial
Set xRow = xRow.Offset(SplitRow)
Next
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Thanks,
Maize
I have read through multiple VBA codes for splitting out row data on a worksheet. What I am specifically trying to do is as follows:
Split out data for every 15 rows of information into their own worksheets.
I want to keep Row and Column widths based on the master sheet.
The master sheet has the first row as a header, and I would like to have that header copy to each sheet.
I found the below code, that split out the rows correctly, but I could not get widths or the header to carry over. All help is greatly greatly greatly appreciated.
Sub SplitData()
'Updateby20140617
Dim WorkRng As Range
Dim xRow As Range
Dim SplitRow As Integer
Dim xWs As Worksheet
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
SplitRow = Application.InputBox("Split Row Num", xTitleId, 5, Type:=1)
Set xWs = WorkRng.Parent
Set xRow = WorkRng.Rows(1)
Application.ScreenUpdating = False
For i = 1 To WorkRng.Rows.Count Step SplitRow
resizeCount = SplitRow
If (WorkRng.Rows.Count - xRow.Row + 1) < SplitRow Then resizeCount = WorkRng.Rows.Count - xRow.Row + 1
xRow.Resize(resizeCount).Copy
Application.Worksheets.Add after:=Application.Worksheets(Application.Worksheets.Count)
Application.ActiveSheet.Range("A1").PasteSpecial
Set xRow = xRow.Offset(SplitRow)
Next
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Thanks,
Maize