Multipage userform with listbox not receiving data from vba filter

Dungadin

New Member
Joined
Mar 16, 2016
Messages
7
I have found so much information thru this forum and learned from you all! I am quite a novice with VBA but find it fascinating! Thank you so much in advance for your help.

Background: My current project is to update and streamline parking lot vehicle information for the school I work at.

The workbook itself is comprised of 4 sheets; Main interface, Data, categories, and Veh. makes and models.

I have created a multi-page user form to enter the data and store it (page 1) and also search for the information and edit or update it (page 2).

On this 2nd page of the userform is a search function which looks up the information and pastes into a separate area of the Data sheet, which should then copy the information to the user-form listbox thru a named range called "outdata". The problem is, it isn't copying to the listbox and it is driving me mad.

What is happening is, I open the userform, type the information I want to find, and I get a programmed error message saying "No match found". When I close the form and open the Data Sheet, the information I searched for is in the area I designated. But for some reason, the data isn't getting transferred to the userform.

There are 22 columns of information

I would like to add a screen pic of the userform, but not sure how.

Here is the VBA code:

Private Sub cmdGetData_Click()
'dim the variables
Dim Crit As Range
Dim FindMe As Range
Dim DataSH As Worksheet​
'error handler
On Error GoTo errHandler:​
'set object variables
Set DataSH = Sheet1​
'hold in memory and stop screen flicker
Application.ScreenUpdating = False​
'///////////////////////////////////////////
'if header is selected add the criteria
If Me.cboHeader.Value <> "All_Columns" Then
If Me.txtSearch = "" Then​
DataSH.Range("AA2") = ""​
Else​
DataSH.Range("AA2") = "*" & Me.txtSearch.Value & "*"​
End If​
End If​
'//////////////////////////////////////////
'if all columns is selected
If Me.cboHeader.Value = "All_Columns" Then​
'find the value in the column
Set FindMe = DataSH.Range("A2:V30000").Find(What:=txtSearch, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)​
'variable for criteria header
Set Crit = DataSH.Cells(1, FindMe.Column)​
'if no criteria is added to the search
If Me.txtSearch = "" Then​
DataSH.Range("AA2") = ""
DataSH.Range("AA1") = ""​
Else​
'add values from the search
DataSH.Range("AA1") = Crit​
If Crit = "ID" Then
DataSH.Range("AA2") = Me.txtSearch.Value​
Else
DataSH.Range("AA2") = "*" & Me.txtSearch.Value & "*"​
End If​
'show in the userform the header that is added
Me.txtAllColumn = DataSH.Range("AA1").Value​
End If​
End If​
'/////////////////////////////////////////
'unprotect all sheets
'Unprotect_All
'filter the data
DataSH.Range("A1").CurrentRegion.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("Data!$AA$1:$AA$2"), CopyToRange:=Range("Data!$AC$1:$AX$1"), _
Unique:=False​
'add the dynamic data to the listbox
lstStudent.RowSource = DataSH.Range("outdata").Address(external:=True)​
'protect all sheets
'Protect_All
'error handler
On Error GoTo 0
Exit Sub
errHandler:
'Protect all sheets
'Protect_All
'if error occurs then show me exactly where the error occurs
MsgBox "No match found for " & txtSearch.Text​
'clear the listbox if no match is found
Me.lstStudent.RowSource = ""​
Exit Sub​
End Sub

multipage%20screenshot.jpg

Thank you
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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