+ Reply to Thread
Results 1 to 6 of 6

Match and copy data between sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    01-22-2015
    Location
    malaysia
    MS-Off Ver
    2010
    Posts
    6

    Match and copy data between sheets

    Hi all.

    I have two sheets. Sheet1 need to be filled daily. After clicking the submit button, the data from Sheet1 will be transferred to Sheet2. Sheet2 will collect the data monthly. There is a cell in Sheet1 where the user need to enter the date. The problem is, how can I copy the data from Sheet1 to Sheet2 according to their respective number of day?

    *there are numbers of day (from 1 to 31) in Sheet2, column A*

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,743

    Re: Match and copy data between sheets

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    01-22-2015
    Location
    malaysia
    MS-Off Ver
    2010
    Posts
    6

    Re: Match and copy data between sheets

    Dear alansidman,

    please assist me.


    thank you in advance.
    Attached Files Attached Files

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,743

    Re: Match and copy data between sheets

    I have developed some VBA code that does what you ask, however, to make it work, you must unmerge all data cells in sheet1. VBA does not like to work with merged cells and if you do not unmerge your cells, this code will fail.

    Option Explicit
    
    Sub ams()
        Dim sh1 As Worksheet, sh2 As Worksheet
        Set sh1 = Sheet1
        Set sh2 = Sheet2
        Dim i As Long
        i = Day(sh1.Range("D3"))
        
        Application.ScreenUpdating = False
        sh1.Range("F7:F13").Copy
        sh2.Range("B" & i + 6).PasteSpecial xlPasteAll, , , True
        Application.Union(sh1.Range("F19"), sh1.Range("H19"), sh1.Range("J19")).Copy sh2.Range("I" & i + 6)
        Application.Union(sh1.Range("F20"), sh1.Range("H20"), sh1.Range("J20")).Copy sh2.Range("L" & i + 6)
        Application.Union(sh1.Range("F21"), sh1.Range("H21"), sh1.Range("J21")).Copy sh2.Range("O" & i + 6)
        sh1.Range("D24").Copy sh2.Range("R" & i + 6)
        sh1.Range("I24").Copy sh2.Range("T" & i + 6)
        Application.CutCopyMode = False
        sh1.Range("F7:F13").ClearContents
        sh1.Range("F19:J21").ClearContents
        sh1.Range("I24").ClearContents
        sh1.Range("D24").ClearContents
        Application.ScreenUpdating = True
        MsgBox "Action Completed"
    End Sub

    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button

  5. #5
    Registered User
    Join Date
    01-22-2015
    Location
    malaysia
    MS-Off Ver
    2010
    Posts
    6

    Re: Match and copy data between sheets

    dear alansidman,

    thanks for your respond. i tried your code and alter a little bit, but it still not working. fyi, in the actual workbook, i am using so many merged cells. it is impossible for me to unmerge them. in additional, i am using offset to copy the data horizontally.

    do you have any idea how the code looks like?


    thank you in advance.

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,743

    Re: Match and copy data between sheets

    What does this mean?
    do you have any idea how the code looks like?
    With out seeing your actual file, I have no idea what anything on your spreadsheet looks like. If you don't wish to unmerge your cells and redesign your worksheet, then you will need to find another means to solve this issue. The solution I provided works for the example you provided. If you wish to determine a solution that works for a different spreadsheet, then we will need to see that spreadsheet.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Match data on 2 sheets and copy value from one cell to another cell
    By melodynallison in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-11-2014, 11:02 PM
  2. [SOLVED] Macro to copy data to other sheets on match
    By Malkier in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-11-2014, 02:25 AM
  3. match data 2 sheets. if match, then copy data from one sheet to another
    By flunzy in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-09-2013, 06:38 AM
  4. Replies: 2
    Last Post: 12-19-2012, 12:25 AM
  5. Replies: 0
    Last Post: 11-27-2012, 10:32 AM

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