Hi guys and or gals,
I'm trying to create a custom seach form for an excel workbook, I got a simple one to work, but i need to get the search within specific ranges, I tried getting the below code to work, but I'm bashing my head against the wall...
Any help would be awesome!
Basically the form has three values
txtName
txtChange
Txtdate
the form should be able to able to search one of the other, none are manditory. I've created the ranges as mentioned in the below code but it keeps falling over...
Code:Private Sub Cmd_OK_Click() Dim MyText As String Dim MyMsg As String Dim MyType Dim MyTitle As String Dim rfoundcell As Range Dim lcount As Long MyText = txtname.Value MyText = txtchange.Value MyText = txtdate.Value MyMsg = "No matches were found." MyType = vbOKOnly + vbExclamation MyTitle = "No Matches" ' Set rfoundcell = Range("Name") Set rfoundcell = Range("Change") Set rfoundcell = Range("Date") On Error GoTo ErrorHandler For lcount = 1 To WorksheetFunction.CountIf(Columns(1), txtname) Set rfoundcell = Columns(1).Find(What:=txtname, After:=rfoundcell, _ LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False) Next lcount For lcount = 1 To WorksheetFunction.CountIf(Columns(1), txtchange) Set rfoundcell = Columns(1).Find(What:=txtchange, After:=rfoundcell, _ LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False) Next lcount For lcount = 1 To WorksheetFunction.CountIf(Columns(1), txtdate) Set rfoundcell = Columns(1).Find(What:=txtdate, After:=rfoundcell, _ LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False) Next lcount Exit Sub ErrorHandler: MsgBox MyMsg, MyType, MyTitle End Sub




Reply With Quote