Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default listbox - How to reset the values

Hello Gurus - I have written a macro on the back of a listbox button that
allows the user to select a worksheet to update. However, once a selection is
made the list box retains this choice so the user cannot select the same
choice again. How do I reset the listbox so none of the options are selected?

Thank you in advance!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default listbox - How to reset the values

Set its .ListIndex to -1

NickHK

"NezRhodes" ...
Hello Gurus - I have written a macro on the back of a listbox button that
allows the user to select a worksheet to update. However, once a selection
is
made the list box retains this choice so the user cannot select the same
choice again. How do I reset the listbox so none of the options are
selected?

Thank you in advance!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default listbox - How to reset the values

Nick

I added this line of script to the end of my macro:

ListBox1.ListIndex = -1

and unfortunately it does not reset the listbox. Can you clarify your answer
a little please?

"NickHK" wrote:

Set its .ListIndex to -1

NickHK

"NezRhodes" ...
Hello Gurus - I have written a macro on the back of a listbox button that
allows the user to select a worksheet to update. However, once a selection
is
made the list box retains this choice so the user cannot select the same
choice again. How do I reset the listbox so none of the options are
selected?

Thank you in advance!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default listbox - How to reset the values

Private Sub ListBox1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
ListBox1.ListIndex = -1
End Sub

--
Regards,
Tom Ogilvy


"NezRhodes" wrote in message
...
Nick

I added this line of script to the end of my macro:

ListBox1.ListIndex = -1

and unfortunately it does not reset the listbox. Can you clarify your
answer
a little please?

"NickHK" wrote:

Set its .ListIndex to -1

NickHK

"NezRhodes"
...
Hello Gurus - I have written a macro on the back of a listbox button
that
allows the user to select a worksheet to update. However, once a
selection
is
made the list box retains this choice so the user cannot select the
same
choice again. How do I reset the listbox so none of the options are
selected?

Thank you in advance!






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default listbox - How to reset the values

Great, perfect super, Thanks Tom! (and Nick HK)

"Tom Ogilvy" wrote:

Private Sub ListBox1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
ListBox1.ListIndex = -1
End Sub

--
Regards,
Tom Ogilvy


"NezRhodes" wrote in message
...
Nick

I added this line of script to the end of my macro:

ListBox1.ListIndex = -1

and unfortunately it does not reset the listbox. Can you clarify your
answer
a little please?

"NickHK" wrote:

Set its .ListIndex to -1

NickHK

"NezRhodes"
...
Hello Gurus - I have written a macro on the back of a listbox button
that
allows the user to select a worksheet to update. However, once a
selection
is
made the list box retains this choice so the user cannot select the
same
choice again. How do I reset the listbox so none of the options are
selected?

Thank you in advance!








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default listbox - How to reset the values

I have used the following:
unload me ' unload userform
UserForm1.Show ' reload same userform, change "UserForm1" with your userform
name

Are there any reasons this is not good to use?

--
Regards

Rick
XP Pro
Office 2007



"Tom Ogilvy" wrote:

Private Sub ListBox1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
ListBox1.ListIndex = -1
End Sub

--
Regards,
Tom Ogilvy


"NezRhodes" wrote in message
...
Nick

I added this line of script to the end of my macro:

ListBox1.ListIndex = -1

and unfortunately it does not reset the listbox. Can you clarify your
answer
a little please?

"NickHK" wrote:

Set its .ListIndex to -1

NickHK

"NezRhodes"
...
Hello Gurus - I have written a macro on the back of a listbox button
that
allows the user to select a worksheet to update. However, once a
selection
is
made the list box retains this choice so the user cannot select the
same
choice again. How do I reset the listbox so none of the options are
selected?

Thank you in advance!






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default listbox - How to reset the values

I found this answer to reseting the value/position of a List Box, but I think
my requirement is somewhat different. BTW, I am trying to write a 'nimble'
application to run in both Excel 11 and Excel 12, so lewt me know if there
are distinctions in your recommendation.

I am building a record using several entry firelds and several List Boxes.
I am *not* triggering the code on the List Box selection, but have a
CommandButton the user clicks when the entire record is ready to save. After
copying the record to a pseudo-database, I want to clear the entry fields and
reset the List Boxes to their original blank value & position. I did put a
statement for each of the List Boxes in the CommandButton routine of the form:
ListBoxA.ListIndex = -1
but that did not work.

Thanks in advance for the help.

Cheers. dj

"Tom Ogilvy" wrote:

Private Sub ListBox1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
ListBox1.ListIndex = -1
End Sub

--
Regards,
Tom Ogilvy


"NezRhodes" wrote in message
...
Nick

I added this line of script to the end of my macro:

ListBox1.ListIndex = -1

and unfortunately it does not reset the listbox. Can you clarify your
answer
a little please?

"NickHK" wrote:

Set its .ListIndex to -1

NickHK

"NezRhodes"
...
Hello Gurus - I have written a macro on the back of a listbox button
that
allows the user to select a worksheet to update. However, once a
selection
is
made the list box retains this choice so the user cannot select the
same
choice again. How do I reset the listbox so none of the options are
selected?

Thank you in advance!






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default listbox - How to reset the values

ListBoxA.ListIndex = -1
is kind of odd. Normally, one does:
ListBox1.ListIndex = -1

Maybe something else is going on. Post a sample xls at a shared site like
4shared.com and we will check it if you like.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default listbox - How to reset the values

"ListBoxA" was arbitrarily used in the posting. I never leave controls with
the default name (i.e. ListBoxn) but give them a meaningful name. In this
case, the actual List Box names include "lb_Facility", lb_CaseManager", etc.
Maybe I am missing something, but I don't see how that has any impact on my
issue. Does it ?

Cheers. dj

"Kenneth Hobson" wrote:

ListBoxA.ListIndex = -1
is kind of odd. Normally, one does:
ListBox1.ListIndex = -1

Maybe something else is going on. Post a sample xls at a shared site like
4shared.com and we will check it if you like.

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default listbox - How to reset the values

I don't see how the selected item would not be reset to nothing then.

If I want to clear a listbox's list I do: ListBox1.Clear

If you are using a RowSource, you need to reset it rather than Clear.
e.g.
Private Sub CommandButton1_Click()
ListBox1.RowSource = ""
End Sub



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default listbox - How to reset the values

As I understand it, you want the listbox items deleted? I see no
ListBox1.Clear as I explained.

If you are not using RowSource to fill the list, then you must be using
AddItem or List. Not sure why you are not using RowSource but then I don't
what all you are doing.

Sometimes, one needs repaint to refresh the userform: Userform1.Repaint

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default listbox - How to reset the values

I am populating the List Box items from cells (which I modify while the
fields in the record are being built) by using the ListFillRange property.

No, I do not want the List Box deleted. I just want it reset to appear with
the <blank item showing, which is the first cell in the ListFillRange.

And, I am not using a UserForm, but have the various entry fields and List
Boxes on a regular worksheet which shows other data. When they user finishes
enter data in several fields and making slections in several List Boxes, she
clicks the "Save" CommandButton. It is in the Sub for that button that I
want to reset the List Boxes after copying & storing the built record.

Clearer ? However, the lb_New_RefBy.ListIndex = -1 does not reset
that List Box.

Thanks for the help.

Cheers. dj

"Kenneth Hobson" wrote:

As I understand it, you want the listbox items deleted? I see no
ListBox1.Clear as I explained.

If you are not using RowSource to fill the list, then you must be using
AddItem or List. Not sure why you are not using RowSource but then I don't
what all you are doing.

Sometimes, one needs repaint to refresh the userform: Userform1.Repaint

  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default listbox - How to reset the values

-1 sets the index to no entry. 0 is the first indexed item so:,
Sheet1.ListBox1.Index = 0, would seem to be what you want.

  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default listbox - How to reset the values

Yes ! Thank you. After struggling with some issue like this, the answer
always looks so obvious.

In the spirit of giving back to anyone else following this thread, the
..ListIndex = 0 does place the first item in the List Box, though it is
highlighted. Following the .ListIndex = 0 with .Value = "" deselects that
item and completely returns the List Box to the initial state.

Kenneth, somewhere I picked up the practice of always having an empty cell
as the first in the list of items. Do you recommend against that ?

Cheers. dj

"Kenneth Hobson" wrote:

-1 sets the index to no entry. 0 is the first indexed item so:,
Sheet1.ListBox1.Index = 0, would seem to be what you want.

  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default listbox - How to reset the values

It depends on your needs. If it works for you, I say go for it.

I have not found a need for such. I have been known to end a list with
something like NA. A similar concept can be used for the first item. A
combobox are may useful for that kind of scenario by using -1 for its index.



  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default listbox - How to reset the values

Thanks.

"Kenneth Hobson" wrote:

It depends on your needs. If it works for you, I say go for it.

I have not found a need for such. I have been known to end a list with
something like NA. A similar concept can be used for the first item. A
combobox are may useful for that kind of scenario by using -1 for its index.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i reset excel to its default values? Tiffany Thai Excel Worksheet Functions 1 February 25th 09 11:39 PM
How can I use this VB script to reset my values on other sheets? trilogy[_4_] Excel Programming 1 August 4th 06 05:10 AM
reset values in select cells 1vagrowr Excel Discussion (Misc queries) 1 December 17th 05 09:52 AM
Fill values into a listbox matching selected values from a combobox Jon[_19_] Excel Programming 4 January 25th 05 04:25 PM
Sorting ListBox results or transposing ListBox values to other cells for sorting Rob[_8_] Excel Programming 1 July 9th 03 04:35 AM


All times are GMT +1. The time now is 01:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"