Solved

Sorting Excel Spreadsheet ??

Posted on 2006-06-16
4
191 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…

744 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

12 Experts available now in Live!

Get 1:1 Help Now