Solved

Find Row Between Two Dates Excel Wookbook

Posted on 2014-02-19
6
436 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 30

Expert Comment

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

Expert Comment

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

Accepted Solution

by:
gowflow earned 500 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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 30

Expert Comment

by:gowflow
ID: 39871335
your welcome.
gowflow
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 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