Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear Listbox

Status
Not open for further replies.

WelshyWizard

IS-IT--Management
Apr 23, 2006
89
GB
I've the following code which updates a listbox when moving from cell to cell (depending upon a value)...

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

  'Get the current row position and the value from the 2nd column in
  'that row.
    
  ListBox1_Populate ActiveCell.Top, Cells(ActiveCell.Row, 2).Value

End Sub
    
Private Sub ListBox1_Populate(NewTop As Long, Optional ContractNumber As String)

    Dim wksLookup As Worksheet
             
    Set wksLookup = Worksheets("PHASING")
           
    celval = 5
    Do
        If wksLookup.Range("C" & celval) = ContractNumber Then
            ListBox1.AddItem wksLookup.Range("A" & celval) & "      " & Format(wksLookup.Range("B" & celval) & "'%", "")
            celval = celval + 1
            
        Else
        
            celval = celval + 1
                        
        End If
    Loop Until wksLookup.Range("C" & celval) = ""

End Sub

What I want to do is to clear the listbox when moving from a cell, ready for the new values to be entered.

Anyone have any ideas? I tried to use removeallitems with no success.

Cheers

Today is the tomorrow you worried about yesterday - and all is well.....
 
Done it.... The code I used is simply.....

Code:
Listbox1.clear

Just thought I'd post it to help out others who search for this subject!

Today is the tomorrow you worried about yesterday - and all is well.....
 
Hi,

I am having this problem in access but the Listbox1.clear gives me an error, can anyone tell me how to clear the listbox in access?

Cheers

Stuart
 
In your module
1) Press F2 to bring up the object model
2) search for Listbox
3) View properties and methods of a listbox
4) Find the RemoveItem method
5) Remember to consult help files in future before posting questions

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
In access:
Me![list box name].RowSource = ""

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top