View Single Post
  #4   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 tested on a userform using 2 ranges "test" & "test1"

used the line of code:

Private Sub ListBox1_AfterUpdate()
If ListBox1.RowSource = "test1" Then
ListBox1.RowSource = "test"
End If
End Sub


this would only work properly AFTER the change event
so I guess my previous post was a mistake...
Hope this helps...




-----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
----------------------------------------------------------

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









.