Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sorting Excel Spreadsheet ??

Posted on 2006-06-16
4
Medium Priority
?
220 Views
Last Modified: 2010-04-30
I have Excel worksheets.
I want to write a code to sort it.
But because I have first three rows as headers.
I need to use 4th row and on to sort it.
Say there are 20 rows so I need to sort from 4th to 20th rows.
Because users will add more rows I won't know the last row numbers.

I want to find out if I can code to sort from 4th row to whatever row I have.
How can I do that if this can be done easily??
Thanks much.

0
Comment
Question by:dkim18
  • 2
4 Comments
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 800 total points
ID: 16921453
how about

ActiveSheet.Range("C5:C" & ActiveSheet.Range("C1").SpecialCells(xlCellTypeLastCell).Row).Sort _
    Key1:=Range("C5"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
0
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 1200 total points
ID: 16928058
Assuming column A is the column to sort upon, and the data will be sorted in ascending alphabetical order:

ActiveSheet.UsedRange.Resize(ActiveSheet.UsedRange.Rows.Count - 3).Offset(3).Sort Key1:=[A4], Order1:=xlAscending

If you wish to sort on, say, column A ascending, then column B descending, then column E ascending...

ActiveSheet.UsedRange.Resize(ActiveSheet.UsedRange.Rows.Count - 3).Offset(3).Sort Key1:=[A4], Order1:=xlAscending, Key2:=[B4], Order2:=xlDescending, Key3:=[E4], Order3:=xlAscending


BFN,

fp.
0
 

Author Comment

by:dkim18
ID: 16942914
Thank so much guys.

0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 16942925
You're very welcome.

Thanks for closing the question.

BFN,

fp.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question