+ Reply to Thread
Results 1 to 4 of 4

Need help getting data from one worksheet to another based on value of adjacent cell

Hybrid View

  1. #1
    Registered User
    Join Date
    09-06-2012
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2003
    Posts
    2

    Need help getting data from one worksheet to another based on value of adjacent cell

    I have a worksheet that receives a monthly raw data dump from a database. This data is organized by the date stamp from the database but I only get data for days in which data was written to the database. Therefore, if data was entered on September 1st and September 3dr the data dump would only include two rows of data. One row for September 1st and one row for September 3rd. There is not a blank row for September 2nd.

    I need to copy this raw data into a formatted worksheet that has a dedicated row for a 31 day month. I need a way to look at the date code of the raw data and use that to copy its associated data to the proper row on the formatted worksheet.

    I presume this would require a macro but I am open to whatever solution works. I would like this macro (or whatever solution might work) to run once whenever the data dump occurs. I've attached a small sample workbook with a "RawData" worksheet and a "FormattedData" worksheet for your review.

    Your help is much appreciated.

    Cheers.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,077

    Re: Need help getting data from one worksheet to another based on value of adjacent cell

    in FormattedData!C3
    =IF(ISNA(VLOOKUP(DATE(YEAR(RawData!$B$3),MONTH(RawData!$B$3),B3),RawData!B$3:C$6,2,FALSE)),"",VLOOKUP(DATE(YEAR(RawData!$B$3),MONTH(RawData!$B$3),B3),RawData!B$3:C$6,2,FALSE))

    and copy down the column
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Need help getting data from one worksheet to another based on value of adjacent cell

    Here is how you can do it the vba way -
    Option Explicit
    
    Sub copy_data()
    Dim lrow As Long, i As Long, j As Long, lastrow As Long
    
    With Worksheets("RawData")
        lrow = .Range("B" & .Rows.Count).End(xlUp).Row
        lastrow = Worksheets("FormattedData").Range("B" & Rows.Count).End(xlUp).Row
        For i = 3 To lrow
            For j = 3 To lastrow
                If Day(.Cells(i, 2)) = Worksheets("FormattedData").Cells(j, 2) Then
                    Worksheets("FormattedData").Cells(j, 3).Value = .Cells(i, 3).Value
                    Exit For
                End If
            Next j
        Next i
    End With
    End Sub
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose Tools | Macro | Macros
    Select a macro in the list, and click the Run button
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Registered User
    Join Date
    09-06-2012
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2003
    Posts
    2

    Smile Re: Need help getting data from one worksheet to another based on value of adjacent cell

    Thanks Special-K! You solution worked perfectly.

    Thanks arlu1201 for the VBA version! I don't VBA much so your example was educational for me.

    Your guys help has solved my problem.

+ 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