Thread: Explain code
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Explain code

Just to add...

You'll want to qualify the ranges here, too:

SortRange.Sort _
Key1:=.Range("A2"), _
Order1:=xlAscending, _
Key2:=.Range("C2"), _
Order2:=xlAscending, _
Header:=xlNo

(I added dots in front of both Range()'s.)

JLGWhiz wrote:

'Qualify the sheet you want to execute on
'using the "With" Statement.

With Sheets(3)

'Assign variable for last row with data in it.

LastRow = .Range("A" & Rows.Count).End(xlUp).Row

'Set the of object variable for the range to search.

Set SortRange = .Rows("2:" & LastRow)

'Execute the sort procedure

SortRange.Sort _
Key1:=Range("A2"), _
Order1:=xlAscending, _
Key2:=Range("C2"), _
Order2:=xlAscending, _
Header:=xlNo

'Close the "With" statement.

End With

"Novice Lee" wrote:

Could someone explain the following code for me I'm new VBA and have never
seen some of these Items

Thanks

With Sheets(3)

LastRow = .Range("A" & Rows.Count).End(xlUp).Row
Set SortRange = .Rows("2:" & LastRow)
SortRange.Sort _
Key1:=Range("A2"), _
Order1:=xlAscending, _
Key2:=Range("C2"), _
Order2:=xlAscending, _
Header:=xlNo
End With


--

Dave Peterson