View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Forum Freak[_2_] Forum Freak[_2_] is offline
external usenet poster
 
Posts: 17
Default VBA code sort problems - recorded macro does not work with userform

Hi

I need to sort a range of cells to put in numerical order. I recorded a
macro but when I transfered it to my userform button I hit problems

The following code sorts but I get a runtime error 13 type mismatch when I
exit the userform.
When I debug it has failed when it should be loading another userform

Sub Mysort1()

Sheets("Lists").Select
Range("CM38:CM42").Select
Selection.Sort Key1:=Range("CM38"), Order1:=xlAscending, Header:=xlGuess
_
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

I tried removing the selection part and used

Sheets("Lists").Range("CM38:CM42").Sort Key1:=Range("CM38"),
Order1:=xlAscending, Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

This time sorting does not take place and I get runtime 1004
The sort reference is not valid. Make sure that it's within the data you
want to sort, and the first SortBy box isn't the same or blank

I have searched the web but have not found a solution

Can anyone see what I am doing wrong.

Kenny
XP pro and office 2003