Search Function - Help

Link1565

New Member
Joined
May 28, 2015
Messages
1
I have a Search function that I found over at The Spreadsheet Guru, which I have altered to suit my own needs, that works great for finding numbers and words, but it is unable to find dates. I was wondering if someone could please help me figure out how I can alter this code so that it can find dates?

On my spreadsheet I have an ActiveX combobox called DateUserSearch that displays all dates listed under the "Date" range. The search function then uses the date the user defines in the combobox as the search reference.

At the moment the search returns no results, even if the date the user has searched for exists within the range.

Thanks in advance,
Link1565

Code:
Sub DateSearchBox()
'PURPOSE: Filter Data on User-Determined Column & Text/Numerical value

Dim myButton As OptionButton
Dim SearchString As String
Dim ColumnSearch As String
Dim sht As Worksheet
Dim myField As Long
Dim DataRange As Range

'Unfilter Data (if necessary)
  On Error Resume Next
    ActiveSheet.ShowAllData
  On Error GoTo 0
  
'Filtered Data Range
  Set DataRange = ActiveSheet.ListObjects("MainTable").Range


'Retrieve User's Search Input
  mySearch = ActiveSheet.DateUserSearch.Text
   'Determine if user is searching for number or text
  If IsNumeric(mySearch) = True Then
    SearchString = "=" & mySearch
  Else
    SearchString = "=*" & mySearch & "*"
  End If
  
'The Column Being Searched
 ColumnSearch = "Date"
    
'Determine Filter Field
  myField = WorksheetFunction.Match(ColumnSearch, DataRange.Rows(1), 0)
   
'Filter Data
  DataRange.AutoFilter _
    Field:=myField, _
    Criteria1:=SearchString, _
    Operator:=xlAnd
    
'Clear search field
ActiveSheet.DateUserSearch.Text = ""


End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,213,527
Messages
6,114,144
Members
448,552
Latest member
WORKINGWITHNOLEADER

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