+ Reply to Thread
Results 1 to 2 of 2

Copy and paste data from Previous Month

Hybrid View

dwalton5 Copy and paste data from... 09-13-2011, 09:31 AM
venkat1926 Re: Copy and paste data from... 09-14-2011, 12:20 AM
  1. #1
    Registered User
    Join Date
    09-01-2011
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    21

    Copy and paste data from Previous Month

    I need to create a macro that will determine the current date and then filter data from the previous month, then copy and paste the results to a different sheet. For example, If today is 9/12/11 and I run the macro I would like to have all data from Row A that has a date between 8/1/11 and 8/31/11 copyied and pasted to Column A on a different sheet.
    A B
    Data Date
    123 8/1/11
    456 8/15/11
    789 8/30/11
    012 9/5/11

    Thanks for the help
    Don

  2. #2
    Valued Forum Contributor
    Join Date
    06-17-2009
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003,excel 2007
    Posts
    678

    Re: Copy and paste data from Previous Month

    try this macro (main data in sheet1 and result in sheet2)

    Sub test()
    Dim d As Date, r As Range, cfind As Range
    d = CDate(Date)
    'MsgBox d
    With Worksheets("sheet1")
    .Range("C2").FormulaR1C1 = "=MONTH(RC[-1])"
    .Range("c2").Copy Range(.Range("c2"), Range("c2").Offset(0, -1).End(xlDown).Offset(0, 1))
    Set r = .Range("A1").CurrentRegion
    r.AutoFilter field:=3, Criteria1:=Month(d) - 1
    r.Offset(1, 0).Resize(r.Rows.Count - 1, r.Columns.Count).SpecialCells(xlCellTypeVisible).Copy
    With Worksheets("sheet2")
    .Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial
    End With
    r.AutoFilter
    End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1