Hi All, i was hoping somebody may be able to spare some time to help with the following....
http://www.ozgrid.com/forum/showthread.php?t=172993
The thread above helped me to populate a multi-column Listbox by copying and pasting autofiltered rows to another sheet and using the newly pasted rows as a named range to populate the listbox. The code below works great...
Private Sub CommandButton1_Click() Dim sCriteria As String, rngList As Range, sRngAddress As String
sCriteria = Me.txtCriteria.Value
With Sheet2
.AutoFilterMode = False
'below is set up to filter the values in the second coloumn only
.Range("A1:F" & .Cells(Rows.Count, "B").End(xlUp).Row).AutoFilter field:=2, Criteria1:=sCriteria
Set rngList = .Range("A1:F" & .Cells(Rows.Count, "B").End(xlUp).Row).SpecialCells(xlCellTypeVisible)
Sheet3.Cells.ClearContents
rngList.Copy Sheet3.Range("A1")
sRngAddress = "Sheet3!" & .Range("A1").CurrentRegion.Address
End With
With Me.ListBox1
.RowSource = sRngAddress
End With
Set rngList = Nothing
End Sub
Display More
However, for a different application I have tried to ammend the code above to work with a single column listbox in the following way but keep getting an error at the line highlighted in red. the sheet is filtered and the filtered rows are pasted into a new sheet but the listbox won't pick up the sRngAddress...
Private Sub cmdAddressSearch_Click()
Dim rngList As Range, sRngAddress As String
With Sheet15
.AutoFilterMode = False
.Range("A1:A" & .Cells(Rows.Count, "A").End(xlUp).Row).AutoFilter field:=1, Criteria1:="*" & txtCriteria.Value & "*", Operator:=xlAnd
Set rngList = .Range("A1:A" & .Cells(Rows.Count, "A").End(xlUp).Row).SpecialCells(xlCellTypeVisible)
Sheet16.Cells.ClearContents
rngList.Copy Sheet16.Range("A1")
sRngAddress = "Sheet16!" & .Range("A1").CurrentRegion.Address
End With
With Me.ListBox1
.RowSource = sRngAddress
End With
Set rngList = Nothing
End Sub
Display More
The error is...
Run-time error '380'.
Could not set the rowsource Property. Invalid Property Value.
If anyone has any thoughts on this i would be most grateful. Thanks in anticipation, best regards, Jay