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

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
Who is Participating?
aikimarkConnect With a Mentor Commented:
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.
RayneAuthor Commented:
Hello Dear Experts,

Also Another Additional question: Is is possible to sort a column in sheet without actually activating the sheet?
RayneAuthor Commented:
Weird stuff - now I dont need to activate and its working, strange...Thank you Aikimark
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.