View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] brentfid@hotmail.com is offline
external usenet poster
 
Posts: 7
Default Application-Defined or Object-Defined Error on simple code

I have the following code that produces an Application defined or
object defined error:

Sub SortStyleList()
Dim SortRange As Range

With Sheets("Cost&Margin")
SortRange = .Range(.Range("C1002"), Range("c1002").End(xlDown))
UnprotectAll
SortRange.Sort Key1:=.Range("C1002")
ProtectAll
End With

End Sub


But the following code works flawlessly.

Range("C1002", Range("C1002").End(xlDown)).Select
Selection.Sort Key1:=Range("C1002")

I do not want to select the range. What am I doing wrong?

Thanks,

Brent