filtered data showing on listbox - userform

gkisacik

New Member
Joined
Oct 29, 2018
Messages
24
Hi,

i am trying to figure out why the following code doesnt show only filtered data on the listbox. Can someone help me please?


Dim rData As Range
With Blad1
Set rData = .Range(.Cells(1, 1), .Cells(.Rows.Count, 5).End(xlUp))
If Not .AutoFilterMode Then .Cells(1, 1).AutoFilter
.Cells(1, 1).AutoFilter field:=5, Criteria1:=txtuser.Text
On Error Resume Next
Set rSource = .AutoFilter.Range.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
.Cells(1, 200).CurrentRegion.ClearContents
rSource.Copy .Cells(1, 200)
Set rSource = .Cells(1, 200).CurrentRegion
Set rSource = rSource.Offset(1, 0).Resize(rSource.Rows.Count - 1, rSource.Columns.Count)
With frmmain.ListBox1
.RowSource = ""
.RowSource = rSource.Address(external:=True)
End With
End With
Unload Me
End If


Thanks,

Gokhan Kisacik
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Do you have any merged cells?

Also there is a error on this line
Code:
.UsedRange.AutoFilter field:=15, Criteria1:=Me.txtuser.Text
The 15 should be 5
 
Upvote 0
Do you have any hidden columns, or merged cells?
 
Upvote 0
Have you checked what rSource actually is?
Code:
Debug.Print rSource.Address(External:=True)
 
Upvote 0
sorry got it now with Debug Print thing. found out that Cells (1,200) with data disturbing origin database. When filtering it takes unwanted rows on listbox.

Thanks Norie for giving me a good direction.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top