Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 





Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Microsoft Support > Microsoft Office support
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read

Microsoft Office support MS Office support forum

Reply
 
Thread Tools
Old 07-09-2008, 08:04 PM   #1 (permalink)
Registered User
 
Join Date: Jul 2008
Posts: 3
OS: xp


excel list: allow new entries then alphabetize

Hi All,

I'm trying to make an excel sheet where:
- a cell in sheet 1 has a list of options for the user to choose from, but where the user can also enter his own entry
- sheet 2 contains the list. when the user adds an entry, it's added to the list, and the list automatically alphabetizes itself.

I've gotten this to work, but for some reason, it always stops working. I think that right after I code it, save it and test it, it works. But then if I exit out of the code and start it over, it seems to stop working.

I'd really appreciate your help! Thanks!

Kate

1) Add a list of names to column L of sheet 2. Go to insert->name->define and name it 'List1' saying that it refers to '=OFFSET(Sheet2!$L$1,0,0,COUNTA(Sheet2!$L:$L),1)'. Same thing for column R, making the name='List2' and referring to: '=OFFSET(Sheet2!$R$1,0,0,COUNTA(Sheet2!$R:$R),1)'.

2) Select column L of sheet 1, go to data->validation, select allow "list" , source: "List1", turn error alert off. Same thing for column M, but with source: "List2"

3) Right click on "Sheet 1", go to "View code" and enter:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim lReply As Long
If Target.Cells.Count > 1 Then Exit Sub
If Target.Column = 12 Then
If IsEmpty(Target) Then Exit Sub
If WorksheetFunction.CountIf(Worksheets("Sheet2").Range("List1"), Target) = 0 Then
lReply = MsgBox("Add " & Target & " to list", vbYesNo + vbQuestion)
If lReply = vbYes Then
Worksheets("Sheet2").Range("List1").Cells(Worksheets("Sheet2").Range("List1").Rows.Count + 1, 1) = Target
End If
End If
End If
If Target.Column = 13 Then
If IsEmpty(Target) Then Exit Sub
If WorksheetFunction.CountIf(Worksheets("Sheet2").Range("List2"), Target) = 0 Then
lReply = MsgBox("Add " & Target & " to list", vbYesNo + vbQuestion)
If lReply = vbYes Then
Worksheets("Sheet2").Range("List2").Cells(Worksheets("Sheet2").Range("List2").Rows.Count + 1, 1) = Target
End If
End If
End If
End Sub

4) Right click on "Sheet 2", go to "View code" and enter:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
On Error GoTo ErrHandler
Application.EnableEvents = False
Range("List1").Sort key1:=Range("List1")(1), _
order1:=xlAscending

Range("List2").Sort key1:=Range("List2")(1), _
order1:=xlAscending

ErrHandler:
Application.EnableEvents = True
End Sub
kate84 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 07-09-2008, 09:51 PM   #2 (permalink)
Registered User
 
Join Date: May 2008
Location: Baltimore, Maryland
Posts: 92
OS: Windows XP SP3


Re: excel list: allow new entries then alphabetize

You've done a fine job with this code.

In the code for Sheet2, you have this line of code:

Application.EnableEvents = False

and then at the end of the code:

Application.EnableEvents = True

Here's a word of caution. One thing that can cause the program to stop working is the code being interrupted after setting EnableEvents to False, before it has a chance to set it back to True.
David M58 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 07-10-2008, 07:32 AM   #3 (permalink)
Registered User
 
Join Date: Jul 2008
Posts: 3
OS: xp


Re: excel list: allow new entries then alphabetize

Thanks for your help. That seems to be working. I was wondering if you had advice about one other issue that I'm having:

In sheet 2, I have a list L1. In sheet 1, I have a column (L) that allows the user to select names from the list. In sheet 2, I'd then like to count the number of occurrences of each of the specific names from the list in sheet 1. I am accomplishing this by the following formula:

=COUNTIF(Sheet1!L:L,L1)

However, I also have another column (O) that may be filled in with a name or may be left empty. I'd like to repeat the above calculation of counting the number of occurrences of the name in column L, but only if there is a name selected in column O. Initially, in worksheet 3, I made every cell an if statement. So for a cell in row i, column j, I'd say, if there was a value is row i, column O of sheet 1, make the cell equal to the value in row i, column j of sheet 1. Otherwise, set it to 0. Then I could use the same countif statement from above, but just refer to sheet3. However, this made my file size absolutely huge.

Do you know of another way to do this?

Thank you!

Kate
kate84 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 07-10-2008, 02:50 PM   #4 (permalink)
Registered User
 
Join Date: May 2008
Location: Baltimore, Maryland
Posts: 92
OS: Windows XP SP3


Re: excel list: allow new entries then alphabetize

Here's some information you might find useful.

For example, let's suppose that the user has made the following entries on Sheet1 in column L and column O:

Code:
COLUMN L     COLUMN O
Baltimore    Maryland
Atlanta      Georgia
Oakland      [Blank cell]
Atlanta      [Blank cell]
Pittsburgh   Pennsylvania
Baltimore    Maryland
Chicago      [Blank cell]

Let's suppose that Sheet2 contains the following data in column L:

Code:
COLUMN L
Atlanta
Baltimore
Boston
Chicago
Oakland
Pittsburgh

For each item in column L on Sheet2, if you wanted to show the number of times that item appears on the Sheet1 list, but only counting those occurrences where an entry was made in column O on Sheet1, you could put the following array formula in cell K1 on Sheet2:

Code:
{=COUNT(IF((Sheet1!$L$1:$L$10000=$L1)*(NOT(ISBLANK(Sheet1!$O$1:$O$10000))),1))}

Remember to use Ctrl-Shift-Enter to enter array formulas (you do not type the { and } characters).

In the above example, cell K1 should show 1 since although Atlanta appears on the Sheet1 list twice (in L2 and L4), a corresponding entry in column O appears only once for Atlanta. The formula for cell K2 should return 2 since both Sheet1 entries for Baltimore have a corresponding entry in column O. The formula for cell K3 should return zero since Boston is not entered on Sheet1.
David M58 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 07-12-2008, 07:24 PM   #5 (permalink)
Registered User
 
Join Date: Jul 2008
Posts: 3
OS: xp


Re: excel list: allow new entries then alphabetize

Thanks!
kate84 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -7. The time now is 01:33 PM.



Copyright 2001 - 2008, Tech Support Forum

Search Engine Friendly URLs by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81