Copy in a new sheeet, rows that have a certain date in them

daniels012

Well-known Member
Joined
Jan 13, 2005
Messages
5,219
Using code:
How can I copy rows that have specific dates from a sheet named "Total" to the current sheet I am in?

Rather than manually copying and pasting, it would be much easier if I could do it using code.

Any Ideas?

Michael
 
I am soooooo close
I just can figure out what to put here:
If c.Value <= "12/18/2005"
I need the cell value to be the previous month from the current one!!!!


Michael :oops:
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
in Total Worksheet cell E2 type =today()

replace IF statement with:


If format(c.Value,"MMM") = Format(DateAdd("m", -1, e2), "MMM") Then


This will copy all rows where the MONTH of the date in cell is = the MONTH of today - one month
 
Upvote 0
That is soooooooooo close.
It gives me November from every year previous!! If I use Year as well in the formula, will that work? I know it won't work for January 2006 but I'll get over it!!


Thank you KMiles o_O

Michael
 
Upvote 0
Here is the part of what I have that pertains to dates:

Code:
Dim c As Range, ws As Worksheet
    
    Set ws = Worksheets("Running Total")

    For Each c In ws.Range("K:K")
    If Format(c.Value, "MMM-YYYY") = Format(DateAdd("m", -1, e2), "MMM-YYYY") Then
    c.EntireRow.Copy
    ActiveSheet.Paste
    ActiveCell.Offset(1, 0).Select
    End If
    Next

I could enter a range on the sheet in cells E3 and E4. that has the start and end date and then somehow enter a between function???

Michael
 
Upvote 0
What can I change?????

If Format(c.Value, "MMM-YYYY") = Format(DateAdd("m", -1, e2), "MMM-YYYY")


Michael
 
Upvote 0
This is the one that worked the best. What can I add to get the year also?
If format(c.Value,"MMM") = Format(DateAdd("m", -1, e2), "MMM") Then

Michael
 
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,393
Members
449,446
Latest member
CodeCybear

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