
Originally Posted by
MarvinP
You have two For statements and only one Next statement
For rw = 2 + ---Titles To LR
For I = 2 To LastRowCrit
Next I
You need a
Next rw
somewhere in your code.
Hi Marvin,
Thanks for the help. While you where responding, I have made up the code beneath. The error doesn't shows up but the macro doesn't does the thing that he has to do. In stead of grouping all numbers and place them into seperate sheets, it copies all data and pastes them in every sheet.
Option Explicit
Sub SplitDataNrows()
Dim n As Long, rw As Long, LR As Long, Titles As Boolean
Dim wsAll As Worksheet
Dim wsCrit As Worksheet
Dim wsNew As Worksheet
Dim LastRow As Long
Dim LastRowCrit As Long
Dim I As Long
Set wsAll = Worksheets("split")
If MsgBox("Do you want to split?", ?", vbYesNo, _
"Split") = vbNo Then Exit Sub
Application.ScreenUpdating = False
With ActiveSheet
LR = .Range("A" & .Rows.Count).End(xlUp).Row
For rw = 2 + ---Titles To LR
Sheets("testletter").Select
Sheets("testletter").Copy After:=Sheets(3)
'Kopieert gegevens van hoofdsheet naar brief
LastRow = wsAll.Range("A" & Rows.Count).End(xlUp).Row
.Rows(1).Copy Range("A1")
wsAll.Range("A2:A" & LastRow).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheets("testletter").Range("A2"), Unique:=True
LastRowCrit = Sheets("testletter").Range("A" & Rows.Count).End(xlUp).Row
For I = 2 To LastRowCrit
wsAll.Rows("1:" & LastRow).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Sheets("testletter").Range("A1:A2"), _
CopyToRange:=Sheets("testletter").Range("A1"), Unique:=False
Next I
Next rw
End With
Application.ScreenUpdating = True
End Sub
Bookmarks