Hello,
I have a custom tab from UI Editor. I keep getting 'For without Next' error and it highlights the End Sub. Have no idea why. Please help!
I have a custom tab from UI Editor. I keep getting 'For without Next' error and it highlights the End Sub. Have no idea why. Please help!
Code:
Sub DC_Split(Optional ByVal Control As IRibbonControl)
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Add2 _
Key:=Range("W11:ND11"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveSheet.Sort
.SetRange Range("W1:ND300")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
'delete all worksheets except Frozen Allocation Worksheet
Dim ws As Worksheet
For Each ws In Application.ActiveWorkbook.Worksheets
If ws.Name <> "Frozen Allocation Worksheet" Then
ws.Delete
End If
Dim VendorType As String
On Error Resume Next
VendorType = InputBox("UNFI OR KeHE?", "Vendor Type", "type unfi or kehe")
If VendorType = "unfi" Then
For numtimes = 1 To 10
ActiveSheet.Copy after:=ActiveWorkbook.Sheets(Sheets.Count)
'name each tab
ActiveSheet.Name = "YORK"
ActiveSheet.Name = "SARASOTA"
ActiveSheet.Name = "ROCKLIN"
ActiveSheet.Name = "RIDGEFIELD"
ActiveSheet.Name = "MORENO VALLEY"
ActiveSheet.Name = "LANCASTER"
ActiveSheet.Name = "IOWA"
ActiveSheet.Name = "GILROY"
ActiveSheet.Name = "DENVER"
ActiveSheet.Name = "ATLANTA"
Next numtimes
Call Delete_unfiDC_Frozen
End If
If VendorType = "kehe" Then
For numtimes = 1 To 5
ActiveSheet.Copy after:=ActiveWorkbook.Sheets(Sheets.Count)
'name each tab
Sheets("Dairy Allocation Worksheet (2)").Name = "AURORA"
Sheets("Dairy Allocation Worksheet (3)").Name = "CHINO"
Sheets("Dairy Allocation Worksheet (4)").Name = "DGV"
Sheets("Dairy Allocation Worksheet (5)").Name = "FLM"
Sheets("Dairy Allocation Worksheet (6)").Name = "STOCKTON"
Next numtimes
Call Delete_KeHEDC_Frozen
End If
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Last edited by a moderator: