Runtime Error 1004: Sorting on Non-Active & Hidden Sheet

dariuzthepole

Board Regular
Joined
Jul 23, 2008
Messages
111
Hi Folks,

I've seen a lot of posts similar to this problem and while I have tried to follow the suggested steps, none seem to be working for me.

I'm attempting to copy a small range of formulas, pasting these in the adjacent column as values, then sorting these values alphabetically top down. It is the sorting part that seems to be causing the error (see code below).

Code:
Dim groups As Range
Dim target As Range
Set groups = Worksheets("3rdPlace").Range("L2:L5")
Set target = Worksheets("3rdPlace").Range("M2:M5")


Application.ScreenUpdating = False


    groups.Copy
    target.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
      
    target.Sort
    ActiveWorkbook.Worksheets("3rdPlace").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("3rdPlace").Sort.SortFields.Add Key:=Range("M2"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortTextAsNumbers
    With ActiveWorkbook.Worksheets("3rdPlace").Sort
        .SetRange Range("M2:M5")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
   End With

I'm using 2010 and this sheet is hidden and protected. Any help would be greatly appreciated!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
What is the problem?

For starters in your code you are sorting three times, But I am assuming you want to show which sort methods you used.

But what is not happening or where do you get an error.?

Is your sheet protected allowing sorts?
What happens if you unhide unprotect the sheet?
 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,948
Members
449,198
Latest member
MhammadishaqKhan

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