Alberto15
New Member
- Joined
- Jun 30, 2021
- Messages
- 7
- Office Version
- 365
- 2019
- 2016
- 2013
- Platform
- Windows
- MacOS
- Web
Hello all,
Trust you're good. I got this script from Kutools that allow me to split data into sheets. For example I need to split 1 sheet of 5000 rows into 5 sheets of 1000 rows. My issue is that when splitting the sheet, it decrease the rows by 1000 only (sheet 1 5000 rows, sheet 2 4000 rows, sheet 3 3000 rows). Instead of copying I tried to cut but I got blank excel then i tried to delete the exceeding rows and i got errors.
Grateful if you could help.
Trust you're good. I got this script from Kutools that allow me to split data into sheets. For example I need to split 1 sheet of 5000 rows into 5 sheets of 1000 rows. My issue is that when splitting the sheet, it decrease the rows by 1000 only (sheet 1 5000 rows, sheet 2 4000 rows, sheet 3 3000 rows). Instead of copying I tried to cut but I got blank excel then i tried to delete the exceeding rows and i got errors.
Grateful if you could help.
VBA Code:
'split data into Sheets
Sub SplitDataIntoSheets()
Dim WorkRng As Range
Dim NumRow As Range
Dim SplitRow As Integer
Dim ws As Worksheet
On Error Resume Next
TitleID = "Distribution"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Press Ctrl A then modify $A$1 to $A$2", TitleID, WorkRng.Address, Type:=8)
SplitRow = Application.InputBox("Number of rows", TitleID, 800, Type:=1)
Set ws = WorkRng.Parent
Set NumRow = 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 - NumRow.Row + 1
NumRow.Resize(resizeCount).Copy
Application.Worksheets.Add after:=Application.Worksheets(Application.Worksheets.Count)
Application.ActiveSheet.Range("A2").PasteSpecial
Set NumRow = NumRow.Offset(SplitRow)
Next
Application.CutCopyMode = False
Application.ScreenUpdating = False
End Sub