Search by approval date coding issue

Craw

New Member
Joined
Jul 27, 2011
Messages
32
Greetings,
I am trying to get this code to work. It works when i'm searching for text but I can't seem to get it to search for approval dates (dd-mm-yyyy) that are in a spreadsheet i created.

Private Sub approvalsearch_Click()

Dim strName As String
Dim caption As String
Dim Prompt As String

Prompt = "What Approval Date Would You Like to Search For?"
caption = "Approval Date Search"
strName = Val(InputBox(Prompt, caption))

Range("Table_owssvr_1[Approval Date]").Select
Selection.AutoFilter Field:=6, Criteria1:="=*" & strName & ", Operator:=xlAnd"

End Sub

Any ideas on how to fix it?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try this

Code:
Private Sub approvalsearch_Click()

Dim strName As Date
Dim caption As String
Dim Prompt As String

Prompt = "What Approval Date Would You Like to Search For?"
caption = "Approval Date Search"
strName = DateValue(InputBox(Prompt, caption))

Range("Table_owssvr_1[Approval Date]").Select
Selection.AutoFilter Field:=6, Criteria1:=strName, Operator:=xlAnd

End Sub

This is very similar to your previous thread and you should really have continued there. Please see rule #9 here: http://www.mrexcel.com/forum/showthread.php?t=99490).
 
Upvote 0
My apologies, that code you suggested did not work but I will look at it again.

Regards,

Craw
 
Upvote 0
I just can't seem to get that code to work and the cells its accessing are already formated as dates but they show up as dd/mm/yyyy.
 
Upvote 0
Dates can be a pain to work with in VBA. Maybe

Code:
Private Sub approvalsearch_Click()

Dim strName As Variant
Dim caption As String
Dim Prompt As String

Prompt = "What Approval Date Would You Like to Search For?"
caption = "Approval Date Search"
strName = DateValue(InputBox(Prompt, caption))

Range("Table_owssvr_1[Approval Date]").Select
Selection.AutoFilter Field:=6, Criteria1:=CLng(strName), Operator:=xlAnd

End Sub
 
Upvote 0
Thank you peter it worked like a charm. I was wondering if it would be possible to use the same code but to make it search for dates withing a range? The user would be prompted by an inputbox to input the dates between which he would like to search.

Thanks again,

Craw
 
Upvote 0
Maybe like this

Code:
Private Sub approvalsearch_Click()

Dim strName1 As Variant, strName2 As Variant
Dim caption As String
Dim Prompt As String

Prompt = "What Approval Date Would You Like to Search For?"
caption = "Approval Date Search"
strName1 = DateValue(InputBox(Prompt & " FIRST DATE", caption))
strName2 = DateValue(InputBox(Prompt & " LAST DATE", caption))

Range("Table_owssvr_1[Approval Date]").Select
Selection.AutoFilter Field:=6, Criteria1:=">=" & CLng(strName1), Criteria2:="<=" & CLng(strName2), Operator:=xlAnd

End Sub
 
Upvote 0
The code seems to filter out the items that fit between the dates I am looking for and instread leave only the rows that have a blank in the approval date column. Is there a way to filter out the approval column cells that are blank?

Best Regards,

Craw
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,799
Members
452,943
Latest member
Newbie4296

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