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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

maabadi

Well-known Member
Joined
Oct 22, 2012
Messages
2,681
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Welcome to MrExcel Message Board.
Please show result that you want also.
 

abhi221996

New Member
Joined
Sep 29, 2021
Messages
35
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
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: 9
  • SplittedSheet(1).PNG
    SplittedSheet(1).PNG
    67.2 KB · Views: 9
  • SplittedSheet(2).PNG
    SplittedSheet(2).PNG
    66.9 KB · Views: 9
  • SplittedSheet(3).PNG
    SplittedSheet(3).PNG
    63.9 KB · Views: 9

maabadi

Well-known Member
Joined
Oct 22, 2012
Messages
2,681
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
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
 
Solution

abhi221996

New Member
Joined
Sep 29, 2021
Messages
35
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
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 .
 

Forum statistics

Threads
1,175,515
Messages
5,897,885
Members
434,685
Latest member
datascntst

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
Top