VBA extract data based on between dates

djossh

Board Regular
Joined
Jul 27, 2009
Messages
243
hi, i would like to extract some data based on the date (Between dates) using userform (date start and date end)
example data below

SHEET1
ABCDE
DATEREFCODEAMTNAME
1JAN 2, 2018AAA11125.25STEVE
2JAN 7, 2018ABC123654.00JOHN
3FEB 6, 2018DFS364215.40MICHAEL
4JAN 10, 2018GSS57110.50KURT
5MAR 5, 2018HDS641557.10MIKE
6FEB 15, 2018DSE558211.20JOAN
7FEB 8, 2018JER011321.00HULK
8JAN 26, 2018KYT31764.00SPARK

<tbody>
</tbody>

using my userform :
date start Jan 1, 2018
date end Jan 31, 2018

RESULTS SHOULD BE (NOTE: The column arrangement will be different from the original data)


SHEET2
ABC
DATENAMEAMT
1JAN 2, 2018STEVE25.25
2JAN 7, 2018JOHN654.00
4JAN 10, 2018KURT10.50
8JAN 26, 2018SPARK64.00

<tbody>
</tbody>


thanks in advance for the help
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I would suggest creating a userform with two textboxes that forces the user to write a start and end date in the mm/dd/yyyy format (if that is what your system uses)
<cdate(textbox2.value) then

Code:
Sub timechecker()
LRow = ThisWorkbook.Sheets(2).Cells(ThisWorkbook.Sheets(2).Rows.Count, "A").End(xlUp).Row


With ThisWorkbook.Sheets(1)
   LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row


For Each cell In .Range("A2:A" & LastRow)
If cell.Value > cDate(TextBox1.Value) And cell.Value < CDate(TextBox2.Value) Then
.Range("A" & cell.Row & ":E" & cell.Row).Copy ThisWorkbook.Sheets(2).Range("A" & LRow & ":E" & LRow)


End If
Next cell
End With
End Sub
</cdate(textbox2.value)>
 
Last edited:
Upvote 0
Hi,

try the following and change from your userform the start and end dates from my code Range G1 and H1 set by default

Sub Test()


Dim StartDate As Date, EndDate As Date
Dim RngDate As Range, Rng As Range
Dim LastRow As Integer, k As Integer


'Setup variables


StartDate = Range("G1").Value
EndDate = Range("H1").Value

LastRow = Range("A" & Rows.Count).End(xlUp).Row

Set RngDate = Range("A2:A" & LastRow)

k = 1

For Each Rng In RngDate

If Rng.Value < StartDate Then GoTo Following
If Rng.Value > EndDate Then GoTo Following


Rng.Copy Destination:=Worksheets("Sheet2").Range("A" & k)
Rng.Offset(0, 4).Copy Destination:=Worksheets("Sheet2").Range("A" & k).Offset(0, 1)
Rng.Offset(0, 3).Copy Destination:=Worksheets("Sheet2").Range("A" & k).Offset(0, 2)


k = k + 1

Following:

Next Rng




End Sub
 
Upvote 0
is it possible to start/display the results on Rows 20... I need to add some headers and notes above the results.. thanks
 
Last edited:
Upvote 0
Code:
[COLOR=#333333]LRow = ThisWorkbook.Sheets(2).Cells(ThisWorkbook.Sheets(2).Rows.Count, "A").End(xlUp).Row + 20[/COLOR]
 
Upvote 0
Hi,

try the following and change from your userform the start and end dates from my code Range G1 and H1 set by default

Sub Test()


Dim StartDate As Date, EndDate As Date
Dim RngDate As Range, Rng As Range
Dim LastRow As Integer, k As Integer


'Setup variables


StartDate = Range("G1").Value
EndDate = Range("H1").Value

LastRow = Range("A" & Rows.Count).End(xlUp).Row

Set RngDate = Range("A2:A" & LastRow)

k = 1

For Each Rng In RngDate

If Rng.Value < StartDate Then GoTo Following
If Rng.Value > EndDate Then GoTo Following


Rng.Copy Destination:=Worksheets("Sheet2").Range("A" & k)
Rng.Offset(0, 4).Copy Destination:=Worksheets("Sheet2").Range("A" & k).Offset(0, 1)
Rng.Offset(0, 3).Copy Destination:=Worksheets("Sheet2").Range("A" & k).Offset(0, 2)


k = k + 1

Following:

Next Rng




End Sub

THANKS it possible to start/display the results In Rows 20... I need to add some headers and notes above the results.. thanks
 
Upvote 0

Forum statistics

Threads
1,214,397
Messages
6,119,271
Members
448,882
Latest member
Lorie1693

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