For without Next

temerson

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

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
You don't have a Next ws to go with this loop
Code:
For Each ws In Application.ActiveWorkbook.Worksheets
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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