+ Reply to Thread
Results 1 to 3 of 3

Sort function with variable ranges

  1. #1
    Registered User
    Join Date
    12-03-2009
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2007
    Posts
    1

    Angry Sort function with variable ranges

    I need help. I know it's not the most difficult thing to do, but I just can't figure it out.

    Sounds very easy, but I just can't find any info. Of course maybe because I've been working for the past 12 hours.

    Anyways, here is what I need to do:

    I have a macro that is processing multiple csv files, extracts data from them and than puts into a report. I need to get the files sorted by one of the columns to speed up the data population into the report. The problem is that the csv files have a header of 4 rows that i want to keep intact and just sort the data from row 5 all the way down. I use the below code and it keeps on sorting th whole file including the first 4 rows.

    I would really appreciate if you could help. Thank you in advance.

    With ActiveSheet
    cl = .UsedRange.Columns.Count
    rw = .UsedRange.Rows.Count
    .UsedRange.Select
    End With
    ' *****
    Set MyRange = Selection

    With MyRange
    .Offset(3, 0).Resize(Selection.Rows.Count - 3, Selection.Columns.Count).Select
    End With


    Cells.Sort Key1:=MyRange, Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    Last edited by Vaniok; 12-04-2009 at 11:05 AM. Reason: Changed Title

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: I am stuck :(

    Welcome to the forum,

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Akron, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: I am stuck :(

    Try this, you must change the worksheet name to fit:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1