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
'if header is selected add the criteria
'if all columns is selected
'unprotect all sheets
'Unprotect_All
'filter the data
'Protect_All
'error handler
'Protect all sheets
'Protect_All
'if error occurs then show me exactly where the error occurs
Thank you
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 handlerDim FindMe As Range
Dim DataSH As Worksheet
On Error GoTo errHandler:
'set object variablesSet DataSH = Sheet1
'hold in memory and stop screen flickerApplication.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 columnSet FindMe = DataSH.Range("A2:V30000").Find(What:=txtSearch, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
'variable for criteria headerLookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
Set Crit = DataSH.Cells(1, FindMe.Column)
'if no criteria is added to the searchIf Me.txtSearch = "" Then
DataSH.Range("AA2") = ""
DataSH.Range("AA1") = ""
DataSH.Range("AA1") = ""
Else
'add values from the searchDataSH.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 addedMe.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 listboxCriteriaRange:=Range("Data!$AA$1:$AA$2"), CopyToRange:=Range("Data!$AC$1:$AX$1"), _
Unique:=False
lstStudent.RowSource = DataSH.Range("outdata").Address(external:=True)
'protect all sheets'Protect_All
'error handler
On Error GoTo 0
Exit Sub
errHandler:Exit Sub
'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 foundMe.lstStudent.RowSource = ""
Exit Sub
End SubThank you