Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Find data between dates
I have a macro that is designed to look for dates on one sheet in cells A1
and A2 then match that to dates on another sheet in colum D before putting all the information into a third sheet. I have this macro j = 1 For i = 1 To Sheets("Grades").UsedRange.Rows.Count If (Sheets("Grades").Cells(i, 3) = Sheets("Monthly reporting").Cells(1, 1) And Sheets("Grades").Cells(i, 1) <= Sheets("Monthly reporting").Cells(2, 1)) Then Sheets("Grades").Rows(i).Copy Sheets("Grade calc").Rows(j) j = j + 1 End If Next i and it is not working. Any suggestions |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Find data between dates
Hi Kirsty,
The logic of the code appears OK. However, you say "look for dates on one sheet in cells A1 and A2 then match that to dates on another sheet in colum D" Your code does not look in column D on the second sheet for the match; it is looking in column 1 (or A). Perhaps it should be like this:- For i = 1 To Sheets("Grades").UsedRange.Rows.Count If Sheets("Grades").Cells(i, 3) = _ Sheets("Monthly reporting").Cells(1, 4) And _ Sheets("Grades").Cells(i, 1) <= _ Sheets("Monthly reporting").Cells(2, 4) Then Sheets("Grades").Rows(i).Copy _ Sheets("Grade calc").Rows(j) j = j + 1 End If Next i Did you also know that you can use "D" in lieu of the column number like the following. I agree with someone on this forum that pointed this out to me that it makes the code easier to read and debug if you know exactly what column is being referred to. j = 1 For i = 1 To Sheets("Grades").UsedRange.Rows.Count If Sheets("Grades").Cells(i, 3) = _ Sheets("Monthly reporting").Cells(1, "D") And _ Sheets("Grades").Cells(i, 1) <= _ Sheets("Monthly reporting").Cells(2, "D") Then Sheets("Grades").Rows(i).Copy _ Sheets("Grade calc").Rows(j) j = j + 1 End If Next i -- Regards, OssieMac |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Sumifs with data and dates - I can not figure out the dates | Excel Worksheet Functions | |||
compare 2 tables of dates to find the preceding dates | Excel Worksheet Functions | |||
For Next does not find dates? | Excel Programming | |||
How do I find the earliest dates in a range of dates? | Excel Worksheet Functions | |||
Charting data against dates where dates are not at fixed intervals | Charts and Charting in Excel |