Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Explain code

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Explain code

'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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Explain code

For details of the individual words, you can view
the code in the Visual Basic Editor and highlight
the word you want to know more about, then
press F1. It will display the help file for that word,
if one exists. If not it will tell you that, too.

"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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Explain code

Here is futher explaination on the lastrow

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

Rows.Count in the total number of rows on the worksheet. For excel 2003 it
is 65536, but excel 2007 it is larger.

The end statement has 4 different options
1) xlup
2) xldown
3) xltoleft
4) xltoright

the function end find the first cell that is not empty.

Sol the statemnt is Range("A65536") then move up Column A until a
non-empty cell is found and return the Row number

for last column use this statmen t

Cells(1,Columns.Count).end(xltoleft).Column


Which is Cells(1,256).end(xltoleft).Column

"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

  #5   Report Post  
Posted to microsoft.public.excel.programming
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


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Explain code

Thanks to everyone

Very helpful
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Could Someone Explain this Code Sean Excel Programming 3 March 31st 07 02:13 PM
Please explain code Karen McKenzie Excel Programming 3 March 12th 07 12:04 PM
Would someone explain what this code does? John Smith Excel Programming 0 December 6th 06 01:02 AM
Please Explain Two Lines of Code ca1358 Excel Programming 1 January 18th 06 04:47 PM
Can someone explain this code to me dht[_2_] Excel Programming 1 September 13th 04 12:03 PM


All times are GMT +1. The time now is 06:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"