View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.programming
Jim Tibbetts Jim Tibbetts is offline
external usenet poster
 
Posts: 74
Default Macro doesn't work twice

Tom - I didn't know whether to post this in this thread or the one you have
been helping Rawce in. So I will post it in both. I figured that my problem
with a name being added out of the TeamListBox range would be solved by
sorting the list to move blanks to the bottom. Your code to Rawce seemed like
it should do that. However, I get an error and it flags QuickSort saying "Sub
or Function not defined". How do I define QuickSort?

Thanks

--
Jim T


"Tom Ogilvy" wrote:

Loop through the list and find where you want to place it.

--
Regards,
Tom Ogilvy


"Jim Tibbetts" wrote in message
...
Ok, I have found the problem. The TeamListBox2 IS being updated. However,
TeamListBox2 is set for 10 rows because no team can have more than 10
golfers. TEAMLIST is also 10 rows long. Most of the time there are spaces
at
the end of the list because the team doesn't have 10 golfers. The name
being
added was being added in the 11th space in the list in TeamListBox2
(whether
there were spaces or not) and therefore not showing up in TEAMLIST which
is
being populated by TeamListBox2, which is then used to repopoulate
TeamListBox2 after being sorted. So......how do I get the name to not go
to
the 11th spot but to go to the first empty space?
--
Jim T


"Bob Phillips" wrote:

Jim,

I tried to recreate this and failed miserably.

I assume TEAMLIST is a named range in the workbook?
How is TeamAddsListBox populated, RowSource or AddItem, and from where?
Is TeamAddsListBox a multiselect listbox or single select?

I see the point of loop 1 and loope 2, move the selected item form one
listbox to another and delete from the former (although it is overkill if
it
is a single seelct), but I am lost as to what this code aims to do

Range("TEAMLIST").Value = TeamListBox.List
Range("TEAMLIST").Select
Selection.Replace What:="#N/A", Replacement:=""
Range("TEAMLIST").sort Key1:=Range("TEAMLIST"), Order1:=xlAscending
Range("A84").Select
TeamListBox.List = Range("TEAMLIST").Value

When I ran this bit, TeamListBox filled with many repeated instances on
one
value.


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Jim Tibbetts" wrote in message
...
Thanks for the reply Susan. I added "a=nothing" (without the quotes)
after
the last line but got an error message.
--
Jim T


"Susan" wrote:

try setting your variables to nothing @ the end of the sub.......
a=nothing
just an idea that might help.
susan



On Feb 6, 1:32 pm, Jim Tibbetts
wrote:
OK, I give up. Can someone please tell me why the following macro
works
perfectly the first time the TeamAddsListBox is clicked, but the
second
time
it is clicked, the TEAMLIST range and the TeamListBox are not
updated
from
the TeamAddsListBox.

Private Sub TeamAddsListBox_Click()
For a = 0 To TeamAddsListBox.ListCount - 1
If TeamAddsListBox.Selected(a) Then
TeamListBox.AddItem TeamAddsListBox.List(a)
End If
Next
For a = TeamAddsListBox.ListCount - 1 To 0 Step -1
If TeamAddsListBox.Selected(a) Then
TeamAddsListBox.Selected(a) = False
TeamAddsListBox.RemoveItem a
End If
Next
Range("TEAMLIST").Value = TeamListBox.List
Range("TEAMLIST").Select
Selection.Replace What:="#N/A", Replacement:=""
Range("TEAMLIST").sort Key1:=Range("TEAMLIST"),
Order1:=xlAscending
Range("A84").Select
TeamListBox.List = Range("TEAMLIST").Value
End Sub

If I comment out the last line, the TEAMLIST is updated and sorted
correctly
and the name is added to the TeamListBox, but it is just added onto
the
end
of the list. I need to have the list in the TeamListBox mirror the
list
in
TEAMLIST. The name is removed from the TeamAddsList (as it should
be)
in
either case. I have been stuggling with this all morning. Any help
will
be
greatly appreciated.

Thanks,
--
Jim T