Hello
I am trying to search Data by Date Criteria ie data (from Date) to (to date)
if the Date exists between FromDate toDate then it should display the dates with data Else Date should not be highlited if not exists.
also thought of incorporating "EVALUATE" but i get Type mismatch
the data of date exists in sheet MainData which needs to be searched FromDate ToDate and displayed in Sheet3
Below Code modified from KutoolsforExcel20151202 and incorporating Evaluate Function marked in Red Bold where i get Type mismatch Error
Thanks NimishK
I am trying to search Data by Date Criteria ie data (from Date) to (to date)
if the Date exists between FromDate toDate then it should display the dates with data Else Date should not be highlited if not exists.
also thought of incorporating "EVALUATE" but i get Type mismatch
the data of date exists in sheet MainData which needs to be searched FromDate ToDate and displayed in Sheet3
Below Code modified from KutoolsforExcel20151202 and incorporating Evaluate Function marked in Red Bold where i get Type mismatch Error
Code:
Public Sub dateSearchSub()
Dim xStrSearch As String, xDateSearch As Date
Dim xOut As Worksheet
Dim xWk As Worksheet
Dim xRow As Long, srchdRow As Long
Dim xFound As Range
Dim xStrAddress As String
Dim xUpdate As Boolean
Dim xCount As Long
Dim lstRow As Long
Dim matchRange As Range
Dim a As Integer, b As Integer
Dim matchValueString As String
[COLOR=#ff0000]Dim dv As Long[/COLOR]
[COLOR=#ff0000][B]dv = DateValue(txtToDate) - DateValue(txtFromDate)[/B][/COLOR]
On Error GoTo ErrHandler
''''' 'xDateSearch = Format(txtFromDate.Text, "dd-mm-yy")
[COLOR=#ff0000][B] xDateSearch = Evaluate("datevalue(""" & txtFromDate & """) + (row(1:" & dv + 1 & ")-1)")[/B][/COLOR]
xUpdate = Application.ScreenUpdating
Application.ScreenUpdating = False
Set xOut = Worksheets("Sheet3")
xRow = 1
With xOut
.Cells(xRow, 1) = "Code No."
.Cells(xRow, 2) = "Name"
.Cells(xRow, 3) = "Searched Date"
.Cells(xRow, 4) = "Searched Date in Cell"
.Cells(xRow, 5) = "Amount"
.Cells(xRow, 6) = "Amount Recd."
.Cells(xRow, 7) = "Amount Recivables"
Set xWk = Worksheets("MainData")
[COLOR=#ff0000] Set xFound = xWk.UsedRange.Find(xDateSearch)[/COLOR]
lstRow = xWk.Cells(.Rows.Count, 1).End(xlUp).Row
If Not xFound Is Nothing Then
xStrAddress = xFound.Address
End If
Do
If xFound Is Nothing Then
Exit Do
Else
xCount = xCount + 1
xRow = xRow + 1
.Cells(xRow, 1) = xWk.Range(xWk.Cells(xFound.Row, 1), xWk.Cells(xFound.Row, 1))
.Cells(xRow, 2) = xWk.Range(xWk.Cells(xFound.Row, 2), xWk.Cells(xFound.Row, 2))
.Cells(xRow, 3) = xFound.Value
End If
Set xFound = xWk.Cells.FindNext(after:=xFound)
Loop While xStrAddress <> xFound.Address
End With
MsgBox xCount & "cells have been found"
ExitHandler:
Set xOut = Nothing
Set xWk = Nothing
Application.ScreenUpdating = xUpdate
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
Resume ExitHandler
End Sub
Code:
Public Sub FormR()
'Dim i As Long
'i = DateValue(txtToDate) - DateValue(txtFromDate)
'With Range("A1").Resize(i + 1)
' .Value = Evaluate("datevalue(""" & txtFromDate & """) + (row(1:" & i + 1 & ")-1)")
' .NumberFormat = "dd-mmm-yyyy"
'End With
End Sub
Last edited: