• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 469
  • Last Modified:

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, _
    DataOption1:=xlSortNormal


???

I am getting errors on the above code

Thank you
0
Rayne
Asked:
Rayne
  • 2
1 Solution
 
RayneAuthor Commented:
Hello Dear Experts,

Also Another Additional question: Is is possible to sort a column in sheet without actually activating the sheet?
0
 
aikimarkCommented:
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.
0
 
RayneAuthor Commented:
Weird stuff - now I dont need to activate and its working, strange...Thank you Aikimark
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now