View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
jim c. jim c. is offline
external usenet poster
 
Posts: 16
Default Is refreshing listbox rowsource in listbox click event possible?

I have a project with a similar process.

I "think" the problem is the Exit Event hasn't occured for
your listbox. I notice that changes to my table visually
inside my listbox arn't reflected until focus is passed to
another control, but if a change is made to the table
outside the listbox and the rowsource is reset everything
works fine.

to test this, after your last line of code in your listbox
pass focus to another control...

ie: TextBox1.SetFocus

If i'm incorrect, i would love to know why also. I fight
this often.


-----Original Message-----
Explanation:
The source data the listbox contains is in columns A, B

and C of Sheet1. I
use the rowsource property so the listbox list can have

headers.
"WorkList" is a dynamically updating named range. When a

selection is made
in Listbox1, the selection is moved to the top of the

list on Sheet1 and the
rest of the list is sorted. Everything works great to

that point, the
problem is that when I reset the RowSource property, the

Listbox1 list
doesn't get updated. I assume this is because it is from

Listbox1's click
event, as it works if I do the same thing from another

procedure. Am I
doing something wrong, or is there possibly another way

to accomplish this?

Thanks!
-Jeremy

----------------------------------------------------------

------------------
Private Sub Listbox1_Click()
Dim rng As Range

If DisableFormEvents Then Exit Sub

With Worksheets("Sheet1")
Set rng = .Columns(1).Find(What:=Me.Listbox1,

LookIn:=xlValues)
Range(rng, rng(1, 3)).Cut
.Range("A2").Insert Shift:=xlDown
With Range(.Range("A3"), .Cells(.Rows.Count, 26).End

(xlUp))
.Sort Key1:=Range("A3"), Order1:=xlAscending,
End With
DisableFormEvents = True
Me.Listbox1.RowSource = _
.Names("WorkList").RefersToRange.Address

(External:=True)
DisableFormEvents = False
End With

End Sub
----------------------------------------------------------

------------------









.