For without Next

temerson

New Member
Joined
Apr 22, 2019
Messages
20
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!

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:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,317
Office Version
365
Platform
Windows
You don't have a Next ws to go with this loop
Code:
For Each ws In Application.ActiveWorkbook.Worksheets
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,317
Office Version
365
Platform
Windows
My pleasure.
 

Forum statistics

Threads
1,082,300
Messages
5,364,384
Members
400,796
Latest member
vrcdesktop

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top