+ Reply to Thread
Results 1 to 5 of 5

Copy Data Based on Date Range

Hybrid View

tranjo Copy Data Based on Date Range 05-17-2013, 08:40 AM
Leith Ross Re: Copy Data Based on Date... 05-17-2013, 11:43 AM
AB33 Re: Copy Data Based on Date... 05-17-2013, 12:16 PM
tranjo Re: Copy Data Based on Date... 05-17-2013, 01:12 PM
Leith Ross Re: Copy Data Based on Date... 05-17-2013, 01:30 PM
  1. #1
    Registered User
    Join Date
    05-17-2013
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    2

    Copy Data Based on Date Range

    Hi Everybody,

    I have been struggling to figure this out, I am hoping you guys can help me figure this out.
    I have attached a spreadsheet. I need to copy data from the influent tab and paste it under the proper date in the summary tab.

    I have recorded a macro doing this (see below), only now I need it to automatically go thorugh all rows in the influent tab and automatically find the correct date in the summary tab to paste the row.


    Thanks for your help.

    Sub Copy()
    '
    ' Copy Macro
    '
    
    '
        Rows("2:2").Select
        Selection.Copy
        Sheets("Summary").Select
        ActiveWindow.SmallScroll Down:=81
        Rows("103:103").Select
        ActiveSheet.Paste
        Range("E111").Select
    End Sub
    Book1.xlsx
    Last edited by Leith Ross; 05-17-2013 at 10:45 AM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copy Data Based on Date Range

    Hello tranjo,

    Welcome to the Forum!

    The following macro has been added to the attached workbook. There is a button on the "Influent" sheet to run the macro.

    Sub CopyDateByDate()
    
        Dim Cell        As Range
        Dim cols        As Long
        Dim Data        As Variant
        Dim DstRng      As Range
        Dim LastCell    As Range
        Dim Search      As Range
        Dim SrcRng      As Range
        
            Set SrcRng = Worksheets("Influent").Range("A2")
            Set LastCell = SrcRng.Parent.Cells(Rows.Count, "A").End(xlUp)
            Set SrcRng = SrcRng.Parent.Range(SrcRng, LastCell)
            
            If LastCell.Row < SrcRng.Row Then
                MsgBox "There is No Data to Search.", vbOKOnly + vbExclamation
                Exit Sub
            End If
            
            Set DstRng = Worksheets("Summary").Range("A2")
            Set LastCell = DstRng.Parent.Cells(Rows.Count, "A").End(xlUp)
            Set DstRng = IIf(LastCell.Row < DstRng.Row, DstRng, DstRng.Parent.Range(DstRng, LastCell))
            
                col = SrcRng.Cells(1, Columns.Count).End(xlToRight).Column
                ReDim Data(1 To cols)
                
                Application.ScreenUpdating = False
                
                With Application.FindFormat
                    .Clear
                    .NumberFormat = SrcRng.Cells(1, 1).NumberFormat
                End With
                
                For Each Cell In SrcRng
                    Set Search = DstRng.Find(Cell, , xlFormulas, xlWhole, xlByRows, xlNext, False, False, True)
                    If Not Search Is Nothing Then
                        Data = Cell.Resize(1, cols).Value
                        Search.Resize(1, cols) = Data
                    End If
                Next Cell
                
                Application.ScreenUpdating = True
                
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copy Data Based on Date Range

    Leith,
    There is an error(Out of script) on

    ReDim Data(1 To cols)

  4. #4
    Registered User
    Join Date
    05-17-2013
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Copy Data Based on Date Range

    Thanks guys!

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copy Data Based on Date Range

    Hello tranjo,

    Sorry, my typing is not very good. I left of the "s" on "cols". The line should be...
        cols = SrcRng.Cells(1, Columns.Count).End(xlToRight).Column

+ 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