Quick Question: Sort a column in Ascending order till the last element

Posted on 2012-08-26
Last Modified: 2012-08-26
Hello All,

This might seem a easy question but I think I am stuck. Assuming the column that i want to sort is column B ....

What is the VBA to sort a column till the last row ?

Set rg = Sheets(Sheet5.Name).Range("B2")   'First header label
Set rg = Sheets(Sheet5.Name).Range(rg, Cells(Rows.Count, rg.Column).End(xlUp))

    rg.Sort Key1:=Sheets(Sheet5.Name).Range("B2"), Order1:=xlAscending, Header:= _
    xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _


I am getting errors on the above code

Thank you
Question by:Rayne

    Author Comment

    Hello Dear Experts,

    Also Another Additional question: Is is possible to sort a column in sheet without actually activating the sheet?
    LVL 44

    Accepted Solution

    What error(s) are you getting?

    I don't see anything in your code that would cause the worksheet to activate.  So the short answer to your secondary question is Yes.  If you are observing worksheet activation, its cause is unknown.

    Author Comment

    Weird stuff - now I dont need to activate and its working, strange...Thank you Aikimark

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
    The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
    The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

    754 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

    20 Experts available now in Live!

    Get 1:1 Help Now