Is not sorting

G

Gisela

I'm new in macro programming and it is not sorting. Can someone help me?

This is the code:

SortData:

'Sort Data worksheet
Dim myrange As Range
Dim LastRow As Variant

Worksheets("Data").Select

'Establish range for sort

'Get the last row of worksheet Data
LastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row

Set myrange = Range("B10:S" & LastRow)

'Sorts ascending by Section ID ("H10")

With myrange
.Sort Key1:=Range("H10"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
 
L

Luke M

Hmm, your macro is sorting for me. You might try changing the part with:

Header:=xlGuess
to
Header:=xlNo 'or xlYes, depending on if row 10 is headers or not
 
D

Dave Peterson

'Sort Data worksheet
Dim myrange As Range
Dim LastRow As Variant

with Worksheets("Data")
'Establish range for sort
'Get the last row of worksheet Data
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
Set myrange = .Range("B10:S" & LastRow)

'Sorts ascending by Section ID ("H10")

With myrange
.Sort Key1:=.columns(7), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
End With

I would never let excel guess if my data had headers--if it's my data, I should
know and specify it.

If this doesn't help, you should explain how the sort fails. If you have simple
formulas like:

='Othersheet'!a99
in column H of the Data worksheet, then excel won't sort your data the way you
want.
 
G

Gisela

Thanks! It worked.

Dave Peterson said:
'Sort Data worksheet
Dim myrange As Range
Dim LastRow As Variant

with Worksheets("Data")
'Establish range for sort
'Get the last row of worksheet Data
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
Set myrange = .Range("B10:S" & LastRow)

'Sorts ascending by Section ID ("H10")

With myrange
.Sort Key1:=.columns(7), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
End With

I would never let excel guess if my data had headers--if it's my data, I should
know and specify it.

If this doesn't help, you should explain how the sort fails. If you have simple
formulas like:

='Othersheet'!a99
in column H of the Data worksheet, then excel won't sort your data the way you
want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top