Solved

Sorting Excel Spreadsheet ??

Posted on 2006-06-16
4
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

751 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