?
Solved

Find Row Between Two Dates Excel Wookbook

Posted on 2014-02-19
6
Medium Priority
?
447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 31

Expert Comment

by:gowflow
ID: 39870758
could you upload a sample ?
gowflow
0
 
LVL 31

Expert Comment

by:gowflow
ID: 39870762
Were are your dates lying ? in what column ? all in the same Column ?
gowflow
0
 
LVL 31

Accepted Solution

by:
gowflow earned 2000 total points
ID: 39870941
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

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

Author Closing Comment

by:shieldsco
ID: 39871152
Works Great - Thanks
0
 
LVL 31

Expert Comment

by:gowflow
ID: 39871335
your welcome.
gowflow
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

777 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