Solved

Find Row Between Two Dates Excel Wookbook

Posted on 2014-02-19
6
403 Views
Last Modified: 2014-02-19
I have an Excel Workbook with 8 tabs. I would like to find all the rows (records) between two dates and put the resulst on a seperate tab (entire row).
0
Comment
Question by:shieldsco
  • 4
  • 2
6 Comments
 
LVL 29

Expert Comment

by:gowflow
Comment Utility
could you upload a sample ?
gowflow
0
 
LVL 29

Expert Comment

by:gowflow
Comment Utility
Were are your dates lying ? in what column ? all in the same Column ?
gowflow
0
 
LVL 29

Accepted Solution

by:
gowflow earned 500 total points
Comment Utility
Well having not answered my questions, I made up a sample workbook with Dates in Col A and here is the code for that

Sub GetData()
Dim WS As Worksheet
Dim WSResult As Worksheet
Dim sDate As String, eDate As String
Dim MaxRow As Long

If MsgBox("This process will lookup all sheets in this workbook for a date range in Col A and will return in this sheet all the rows where the data falls in between the selected dates." & Chr(10) & Chr(10) _
    & "Are you ready to proceed ?", vbQuestion + vbYesNo, "Get Data") = vbYes Then
    
    Set WSResult = Sheets("Results")
    WSResult.Cells.Delete
    
    '---> Start Date
    Do
        sDate = InputBox("Input starting Date: ", "Start Date", Format(Now, "mm/dd/yyyy"))
    Loop Until IsDate(sDate)
    
    '---> End Date
    Do
        eDate = InputBox("Input ending Date: ", "End Date", Format(Now, "mm/dd/yyyy"))
    Loop Until IsDate(eDate)
    
    For Each WS In ActiveWorkbook.Worksheets
        If WS.Name <> "Results" Then
        
            '---> Filter the data as per dates
            WS.UsedRange.AutoFilter field:=1, Criteria1:=">=" & sDate, Operator:=xlAnd, Criteria2:="<=" & eDate
            If WS.Rows.End(xlDown).Row < 1048576 Then
                '---> first time put the header
                If MaxRow = 0 Then
                    WS.Range("1:1").Copy WSResult.Range("A1")
                    MaxRow = 2
                End If
                
                WS.Range("A2", "A" & WS.Rows.End(xlDown).Row).EntireRow.SpecialCells(xlCellTypeVisible).Copy
                WSResult.Range("A" & MaxRow).PasteSpecial
                MaxRow = WSResult.UsedRange.Rows.Count + 1
            End If
            WS.ShowAllData
            
        End If
    Next WS
    
    '---> Advise user
    WSResult.UsedRange.EntireColumn.AutoFit
    If MaxRow - 2 = 0 Then
        MsgBox ("No rows were found in the date range " & sDate & " - " & eDate)
    Else
        MsgBox ("A total of " & MaxRow - 2 & " rows were found in the date range " & sDate & " - " & eDate & " and copied successfully.")
    End If
End If

End Sub

Open in new window


the attached sample workbook is for you to see how it works.
Activate macros and press on the button in sheet Results. Put dates interval when required as start and end date. It verify that dates are indeed dates and not strings or non dates. then it goes thru all the sheets and give the results in sheet Results.

Let me know
gowflow
FindDateRange.xlsm
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:shieldsco
Comment Utility
I was at lunch - yes the dates are all in the same column -- I will test your code
0
 

Author Closing Comment

by:shieldsco
Comment Utility
Works Great - Thanks
0
 
LVL 29

Expert Comment

by:gowflow
Comment Utility
your welcome.
gowflow
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now