PDA

View Full Version : Solved: Error 1004 when trying to sort data



marreco
11-04-2012, 08:09 AM
Hi.
The code below should run on the worksheet "Motivos_Calc" but I'm having an error at runtime

Sub CopySort()
Sheets("Motivos_Calc").Range("G1:I11").Copy Destination:=Sheets("Motivos_Calc").Range("K1")
Range("K1:M11").Select
Call SortUniq
End Sub

Sub SortUniq()
With Sheets("Motivos_Calc").Sort
.SortFields.Clear
.SortFields.Add Range("L1"), xlSortOnValues, xlAscending
.SortFields.Add Range("K1")
.SetRange ActiveSheet.Cells(1).CurrentRegion
.Header = xlYes
.Apply <--Erro 1004
End With

End Sub


Run-time error '1004 ':
The reference classification is not valid. sure if the reference
is among the data you want to sort and box the first
Sort is the same or is blank

mancubus
11-04-2012, 12:24 PM
hi.

change
.SetRange ActiveSheet.Cells(1).CurrentRegion

to
.SetRange Range("K1:M11")

which is your sort range.

marreco
11-04-2012, 02:17 PM
Hi.

was perfect!!

thank you very much!!

mancubus
11-04-2012, 02:19 PM
you are wellcome.