View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Tail Wind Tail Wind is offline
external usenet poster
 
Posts: 24
Default Sort Macro: Help with code.


Thank you Barb.

I cannot work on this again until tonight or tomorrow am. Please stand by
while I try to figure it out on my own. However, I may need to post here
again asking for more help!

Thanks again.

"Barb Reinhardt" wrote:

I'd tweak it a bit to include

Dim myWS as worksheet
Dim SortRange as range

Set myWS = nothing
on error resume next
Set myWS = Sheets("Policy Info")
On error goto 0
if not myWS is nothing then

LastRow = myWS.Cells(myws.Rows.Count, "A").End(xlUp).Row
Set SortRange = myWS.Range("A6:O" & LastRow)
SortRange.Sort Key1:=Range("A6"), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
end if

Do the same for the other sort. I'm guessing it's sorting on the wrong
sheet.

HTH,
Barb Reinhardt



"Tail Wind" wrote:

I have a macro which is to sort the names of two worksheets. Worksheet
"Policy Info" sorts correctly however worksheet "Corn Yields" (sort colunn A
which are names, test data range is A6: P12) does not. Columns C thru P
(data fields) are not sorted. Column A is used for row count and cell A13
yields a FALSE when =ISNUMBER is used to check the contents. My code
follows. I would be most grateful to someone who could debug it as I am,
frankly, out of my league here.

Thanks in advance....


Sheets("Policy Info").Select
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Set SortRange = Range("A6:O" & LastRow)
SortRange.Sort Key1:=Range("A6"), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Sheets("Corn Yields").Select
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Set SortRange = Range("A6:P" & LastRow)
SortRange.Sort Key1:=Range("A6"), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Sheets("Policy Info").Select
End Sub