+ Reply to Thread
Results 1 to 6 of 6

Copy Data, Find Date, Paste data below Date

Hybrid View

dgibson Copy Data, Find Date, Paste... 02-10-2011, 07:50 PM
jeffreybrown Re: Copy Data, Find Date,... 02-10-2011, 08:34 PM
dgibson Re: Copy Data, Find Date,... 02-10-2011, 08:43 PM
jeffreybrown Re: Copy Data, Find Date,... 02-10-2011, 09:21 PM
dgibson Re: Copy Data, Find Date,... 02-10-2011, 09:25 PM
jeffreybrown Re: Copy Data, Find Date,... 02-10-2011, 09:31 PM
  1. #1
    Registered User
    Join Date
    01-25-2011
    Location
    Vancouver
    MS-Off Ver
    Excel 2007
    Posts
    7

    Question Copy Data, Find Date, Paste data below Date

    So I am looking to write a simple script to use today's Date, then on sheet1 copy a set range of cells (eg: C1:C5) then go to sheet 2, Find today's date that is already entered on that sheet and paste the data below the date.

    So If on Sheet2 today's date is in cell B1, paste the data from Sheet1 into cells B2 and below.

    Simple? Questions? I'm completely flustered so any help would be super nice!

    Thanks in advance everyone!
    -Dave
    Last edited by dgibson; 02-10-2011 at 09:25 PM. Reason: SOLVED

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Copy Data, Find Date, Paste data below Date

    Hi Dave,

    Maybe something like...

    Sub Test()
        Dim Found As Range
        Dim ans As String
        Set Found = Sheets("Sheet2").Columns("B").Find(What:=Date, LookIn:=xlValues, LookAt:=xlWhole)
        If Not Found Is Nothing Then
            Sheets("Sheet1").Range("C1:C5").Copy Sheets("Sheet2").Range("B" & Found.Row).Offset(1, 0)
        End If
    End Sub
    HTH
    Regards, Jeff

  3. #3
    Registered User
    Join Date
    01-25-2011
    Location
    Vancouver
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Data, Find Date, Paste data below Date

    I have attached the sample file. I would like to take the values on Sheet "Regression_Report" from B2:B6 and copy them under the correct date on sheet FSR_Metrics.

    Hopefully the attached files makes more sense. I have also attempted to use the script that was provided earlier in this thread however nothing appears to happen
    Attached Files Attached Files

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Copy Data, Find Date, Paste data below Date

    Dates are very tricky in VBA and quite honestly it seems I have not mastered them as of yet, but here is what I have.

    On the FSR_Metrics sheet in row 2 is where I am searching. You have to make sure the date is in the same format as Date in VBA returns.

    Date returns 2/10/2011 so if you make the cell match it will run. Just change the format

    If you can't get it to work I will upload the sample sheet.

    Sub FindToday()
        Dim Found As Range
        Dim rngSrc As Worksheet
        Dim rngDst As Worksheet
        Set rngSrc = ActiveWorkbook.Sheets("Regression_Report")
        Set rngDst = ActiveWorkbook.Sheets("FSR_Metrics")
        Set Found = rngDst.Rows(2).Find(what:=Date, LookIn:=xlValues, lookat:=xlWhole)
    
        If Found Is Nothing Then Exit Sub
            rngSrc.Range("B2:B6").Copy
            rngDst.Cells(Found.Row, Found.Column).Offset(1, 0).PasteSpecial xlPasteValues
            Application.CutCopyMode = False
        
        Set rngSrc = Nothing
        Set rngDst = Nothing
        Set Found = Nothing
    End Sub
    Edit: If you want to keep the same format you can update to
    Set Found = rngDst.Rows(2).Find(what:=Format(Date, "dd-mmm"), LookIn:=xlValues, lookat:=xlWhole)
    Last edited by jeffreybrown; 02-10-2011 at 09:29 PM.

  5. #5
    Registered User
    Join Date
    01-25-2011
    Location
    Vancouver
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Data, Find Date, Paste data below Date

    GOT IT! Thanks so much man! HUGE help

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Copy Data, Find Date, Paste data below Date

    You're welcome...sure glad you got it to work for you.

+ 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