Solved

Categorize and Sort Excel VBA

Posted on 2010-11-08
13
327 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
0
Comment
Question by:ca1358
13 Comments
 
LVL 37

Expert Comment

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

Author Comment

by:ca1358
ID: 34086791
Yes order would have to be Mouse, Dog, Cat
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34086799
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

0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 13

Expert Comment

by:gbanik
ID: 34086878
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.
0
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 500 total points
ID: 34086942
In your case you can simply sort descending since mouse, dog, cat are in reverse alphabetical order; however, if you ever need to do a custom sort, you can create custom lists and it will sort by them.
http://office.microsoft.com/en-us/excel-help/create-or-delete-a-custom-list-for-sorting-and-filling-data-HA010222142.aspx
This is how it sorts weekday and month names.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34086945
gbanik, that was also for your benefit. Custom lists are really cool. They work for sorting and fill down.
0
 

Author Comment

by:ca1358
ID: 34087292
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.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34087457
You just need to define a custom list. Which version of Excel are you using?
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34087465
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.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 34394385
http:#a34086942 Is the best answer. Custom lists work really well for sorting.
0
 
LVL 24

Expert Comment

by:broomee9
ID: 34459671
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.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
powershell add exchange property to a report 12 52
Excel Formula 5 47
sort column using vba 2 20
excel count months in date range 6 15
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

831 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