Split Every n Rows From Worksheet Into New Worksheets

abhi221996

New Member
Joined
Sep 29, 2021
Messages
35
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have a large worksheet. Over 40,000 rows. I want to split rows to new worksheets after every 5 times the list of -999.98 value is repeated in the column after any positive value for example given below.
キャプチャ.PNG
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Welcome to MrExcel Message Board.
Please show result that you want also.
 
Upvote 0
Thank you, and I am glad to part of this Forum.
I want to split the data of the masterSheet in a way that the result given in the splitted sheets by just one click,
after every times the - 999.98 value list appear the data is splitted after the first -999.98 value cell of the forth time appearance of the -999.98 list.
The result i want are displayed in the below pictures
 

Attachments

  • mastersheet.PNG
    mastersheet.PNG
    67.9 KB · Views: 11
  • SplittedSheet(1).PNG
    SplittedSheet(1).PNG
    67.2 KB · Views: 11
  • SplittedSheet(2).PNG
    SplittedSheet(2).PNG
    66.9 KB · Views: 10
  • SplittedSheet(3).PNG
    SplittedSheet(3).PNG
    63.9 KB · Views: 10
Upvote 0
I supposed your data is in Column B to D (based sample data) and in First sheet. then use this macro:
VBA Code:
Sub Test()
Dim Lr As Long, C As Long, F As Long, L As Long, K As Long, i As Long
With Sheets(1)
Lr = .Range("D" & Rows.Count).End(xlUp).Row
C = 1: F = 1: K = 2
For i = 2 To Lr
If .Range("D" & i).Value = -999.98 And .Range("D" & i - 1).Value <> -999.98 Then C = C + 1
If C = 4 Or i = Lr Then
If K > Sheets.Count Then Sheets.Add After:=Sheets(Sheets.Count)
.Range("B" & F & ":D" & i).Copy Sheets(K).Range("B1")
C = 1: F = i + 1: K = K + 1
End If
Next i
End With
End Sub
 
Upvote 0
Solution
Thank you so much it means alot. It worked perfectly. You are True genius.
sorry i am new to vba.
If you could give a little explanation to the code .
 
Upvote 0

Forum statistics

Threads
1,214,797
Messages
6,121,629
Members
449,041
Latest member
Postman24

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