Solved

Sorting Excel Spreadsheet ??

Posted on 2006-06-16
4
195 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 200 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 300 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

813 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now