We help IT Professionals succeed at work.

Categorize and Sort Excel VBA

379 Views
Last Modified: 2012-05-10
Is there any way to have  “mouse” categorize at the top and date sorted ,
then “Dog”, then ”cat”
and when a new line is add, when Column B is entered, this would categorize it again and date ordered?


Dog      10/25/2010
cat      8/19/2010
mouse      8/16/2010
Dog      11/1/2010
mouse      12/1/2010
Dog      8/16/2010
cat      7/1/2010
mouse      11/8/2010
Dog      11/8/2010
cat      10/1/2010
Comment
Watch Question

CERTIFIED EXPERT
Awarded 2010
Top Expert 2013

Commented:
Does mouse have to be at the top? You could just sort by column B then by column A.

Author

Commented:
Yes order would have to be Mouse, Dog, Cat
CERTIFIED EXPERT
Awarded 2010
Top Expert 2013

Commented:
Just sort it descending then.
Add this code to the worksheet to make it automatic.
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B:B")) Is Nothing Then
  Range("A:B").SortSpecial Key1:=Range("A1"), Order1:=xlDescending, Key2:=Range("B1"), Order2:=xlAscending
End If
End Sub

Open in new window

Commented:
Have a helper column that stores 1,2 or 3 based on the column containing Mouse, Dog or Cat. Now sort as you want... based on the helper column and dates.
CERTIFIED EXPERT
Awarded 2010
Top Expert 2013
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Awarded 2010
Top Expert 2013

Commented:
gbanik, that was also for your benefit. Custom lists are really cool. They work for sorting and fill down.

Author

Commented:
I just realize it would be descending but it would not always be the case.  They could be mix up, so how do I define the list once sorted?   So that mouse, cat, dog.
CERTIFIED EXPERT
Awarded 2010
Top Expert 2013

Commented:
You just need to define a custom list. Which version of Excel are you using?
CERTIFIED EXPERT
Awarded 2010
Top Expert 2013

Commented:
2007/2010 from the link I posted:
1.Click the Microsoft Office Button , and then click Excel Options.
2.Click the Popular category, and then under Top options for working with Excel, click Edit Custom Lists.
3.In the Custom Lists box, click NEW LIST, and then type the entries in the List entries box, beginning with the first entry.
Press ENTER after each entry.

4.When the list is complete, click Add.
The items in the list that you selected are added to the Custom lists box.

5.Click OK twice.
CERTIFIED EXPERT
Awarded 2010
Top Expert 2013

Commented:
http:#a34086942 Is the best answer. Custom lists work really well for sorting.
TracyVBA Developer
CERTIFIED EXPERT

Commented:
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.