+ Reply to Thread
Results 1 to 9 of 9

Excel Macro Copy&Past data between 2 sheets

  1. #1
    Registered User
    Join Date
    07-08-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    53

    Excel Macro Copy&Past data between 2 sheets

    Hi All,

    I am searching for a macro such that whenever i press this button (in excel) all the data in the sheet is moved to another sheet.

    The macro would need to
    1) Find which rows in the first sheet contains data
    2) Move all data from the first sheet to the second

    Ive attached a TEST sheet as an example.

    Thanks.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    08-02-2008
    Location
    India
    Posts
    88

    Re: Excel Macro Copy&Past data between 2 sheets

    I am actually searching for similar kind of macro

    See if this helps you!

    http://www.excelforum.com/excel-prog...ting-data.html

  3. #3
    Registered User
    Join Date
    07-08-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Excel Macro Copy&Past data between 2 sheets

    Hi there,
    Thanks a lot for taking your time to reply.=)

    While inserting the code i encountered some problems. I've created a new module in the VBA Project and changed the worksheet name to S1 and S2 respectively. But when i run the sub, it prompts the Macro Name which is Copy_Ma by default. When i click on run, a second prompt appears that 'The macro in this project are disabled' . Ive set the macro settings to disabled all macros with notification. There's no security alert for me to enable macro. I've done every ways even in the excel options to enable the macro but i don't know what is it that i've done wrong here. Why can't i run the sub? Please please help.


    Public Sub Copy_Ma()
    Dim shSo As Worksheet, shDe As Worksheet
    Dim rSo As Range, rDe As Range
    Application.ScreenUpdating = False

    Set shSo = Sheets("Sheet1")
    Set shDe = Sheets("Sheet2")

    Set rSo = shSo.[a2].Resize(shSo.[a2].CurrentRegion.Rows.Count - 1, shSo.[a2].CurrentRegion.Columns.Count - 1)
    Set rDe = shDe.[a65536].End(xlUp).Offset(1)

    rSo.Copy
    rDe.PasteSpecial
    End Sub
    Last edited by Nett; 07-12-2009 at 12:45 PM.

  4. #4
    Registered User
    Join Date
    08-02-2008
    Location
    India
    Posts
    88

    Re: Excel Macro Copy&Past data between 2 sheets

    Not sure why i am not able to download the spreadsheet. Please upload it in xls format

  5. #5
    Registered User
    Join Date
    07-08-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Excel Macro Copy&Past data between 2 sheets

    I'm able to finally run the macro but there's error though. Sorry for any inconvenience caused. I'm really new to this.

  6. #6
    Registered User
    Join Date
    07-08-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Excel Macro Copy&Past data between 2 sheets

    Here's the attached xls format.
    I managed to copy and paste the values by using this code:

    Sub NoCopyAndPaste()
    Sheet2.Range("D11:R11").Copy
    Sheet1.Range("D9:K9".PasteSpecial
    Application.CutCopyMode=False'
    EndSub

    But now the merged cells in Sheet 2 are making the value inserted in Sheet 1 incorrect. Anyone have any idea how i can correct this?
    Attached Files Attached Files
    Last edited by Nett; 07-12-2009 at 02:10 PM.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Excel Macro Copy&Past data between 2 sheets

    Quote Originally Posted by Nett View Post
    But now the merged cells in Sheet 2 are making the value inserted in Sheet 1 incorrect. Anyone have any idea how i can correct this?
    Yes, fix the S2 by removing the merged cells. Merged cells truly shouldn't be used at all, or at least never in cells where actual work is going on. If you need a wider cell, widen the column.

    If you MUST merge a cell, text cells only, never data cells. And by never, I simply mean "not ever".
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  8. #8
    Registered User
    Join Date
    07-08-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Excel Macro Copy&Past data between 2 sheets

    Thanks JBeaucaire!=)
    I found this website with a macro on how to Copy range of cells from one sheet to another sheet matching on date values in Excel. Im trying to apply this on my spreadsheet now instead of using the Copying and Pasting of cell range macro. Hope this will help anyone who might encounter the same problem.
    Here's the link:http://www.techonthenet.com/excel/macros/copy_range.php

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Excel Macro Copy&Past data between 2 sheets

    1) You should still fix your sheet so data cells are not part of merged cells.

    2) If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].


    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated)

+ 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