Worksheet_Change call problems

drewan

New Member
Joined
Nov 25, 2009
Messages
15
Hello, I am using the following code:
Code:
Sub Sort()

    ActiveWorkbook.Worksheets("FDG").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("FDG").Sort.SortFields.Add Key:=Range("B2:B911"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("FDG").Sort
        .SetRange Range("A1:F911")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    For Each y In Range("A2:A1337")
        If Cells(y, 3) <> "" Then
            Worksheet_Change Cells(y, 3)
        Else
        If Cells(y, 4) <> "" Then
            Worksheet_Change Cells(y, 4)
        End If
    Next
        
End Sub
I keep getting a "Next without For" error. I suppose it's because of Worksheet_Change? If so, do I have to supply the argument in some other way or is there no way to make Worksheet_Change work like that?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You need another End If Statement or make the else...if in to an ElseIf, depending on your intent.

You will probably need Next to be Next y as well.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

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