View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Fid[_2_] Fid[_2_] is offline
external usenet poster
 
Posts: 16
Default Runtime Error on Simple Sort

I have the following Code:

Sub CmdSortMe_Click()
UnprotectAll
'above routine unprotects current workbook and worksheet
CreateAllStyleList
'above routine gathers data from 3 worksheets into and array and
writes array to Worksheet("Cost&Margin")

With Worksheets("Cost&Margin")
Dim rg As Range
Set rg = Range("StyleRange")
rg.Sort key1:=rg, order1:=xlAscending
ProtectAll 'routine protects current worksheet and workbook
End With
End Sub

I get the "Run-time error '1004': Application-defined or
object-defined error on the code that sorts.
If I omit calling subroutine CreatAllStyleList the sort code executes
without error.

What am I doing wrong?

Thanks,

Brent