simple report by date (last 7 days) - structure has changed.

splreece

Board Regular
Joined
May 29, 2015
Messages
72
Morning all,

I've been using a great piece of code given generously on this forum, however the structure of the file has now changed and Ive altered the code but the script keeps giving runtime errors.

The file has the following user input cells:

F1 = Date from
H1 = Date to

(so the user can select the date range they want).

----the data----

Each row holds a date (column A) and columns D through M hold customer information needed for the report.

The data that is being searched starts in row 4 (titles are in row 3).


--------Output-------

I need the user to be able to produce a report based on their date range (matching any date in column a against the user input) and then producing a report to include cell data from columns D through M for that particular row.


the report would need to include titles in row 3 automatically and I am struggling to change what I thought were independent variables.

Any thoughts are appreciated:

Current code:#

Sub GetDataBetweenDates()
Dim aData, aResults, aRws, aCols
Dim rws As Long, cols As Long, lr As Long
Dim i As Long, j As Long, x As Long, y As Long
Dim sDate As Long, eDate As Long

aCols = Array(4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
cols = UBound(aCols) - LBound(aCols) + 1
ReDim Preserve aCols(1 To cols)
lr = Range("A" & Rows.Count).End(xlUp).Row
aRws = Evaluate("Row(4:" & lr & ")")
aData = Application.Index(Cells, aRws, aCols)
rws = UBound(aData, 1)
ReDim aResults(1 To rws, 1 To UBound(aCols) - 1)
sDate = Range("F1").Value
eDate = Range("g1").Value
For j = 1 To cols
If j <> 4 Then
y = y + 1
aResults(1, y) = aData(1, j)
End If
Next j
x = 1
For i = 2 To rws
If aData(i, 4) >= sDate Then
If aData(i, 4) <= eDate Then
x = x + 1
y = 0
For j = 1 To cols
If j <> 4 Then
y = y + 1
aResults(x, y) = aData(i, j)
End If
Next j
End If
End If
Next i
Sheets.Add After:=ActiveSheet
Range("A1").Resize(x + 1, cols - 1).Value = aResults
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,215,418
Messages
6,124,793
Members
449,189
Latest member
kristinh

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