Results 1 to 4 of 4

Thread: Macro onClick copy/paste Excel

  1. #1
    Join Date
    Nov 2009
    Posts
    36

    Macro onClick copy/paste Excel

    I need to do something very simple. I find this on Google, I have many things but it did not worked as I want. Clearly I have an Excel file (we'll call file.xls) and within 4 sheets (sheet 1, 2, 3 and 4). Form 1 contains a button that will execute the two macros:

    Macro 1: Copy the contents of the E47 cell (cell with formula) of the sheet4 in cell B11 on the same sheet4 (but only the value ... not the formula)
    Macro 2: copy the contents of cell C57 of Sheet2 in cell C7 of the same Sheet2...

    I know it seems simple to some but I could not find it.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Macro onClick copy/paste Excel

    The macro recorder is effective in this case. The code below is from there, I added the comments and deleted the useless things.
    Code:
    Sub Macro1 () 
    Sheets ("Sheet4"). Select 
    Range ("E47"). Select 
    Selection.Copy 
    Range ("B11"). Select 
    Selection.PasteSpecial Paste: = False 
    Sheets ("Sheet2"). Select 
    Range ("C57"). Select 
    Selection.Copy 
    Range ("C7"). Select 
    Selection.PasteSpecial Paste: = False 
    Sheets ("Sheet1"). Select 
    End Sub

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Macro onClick copy/paste Excel

    This method is the most classic and great to see the full path, but there is also this variant, interesting to learn, quick to write and execute:
    (the destination cell is the VALUE of source cell )

    Code:
    Sub Macro1 () 
    Sheets ("Sheet4"). Range ("B11"). Value = Sheets ("Sheet4"). Range ("E47"). Value 
    Sheets ("Sheet2"). Range ("C7"). Value = Sheets ("Sheet2"). Range ("C57"). Value 
    End Sub
    And it avoids any movement.

    In fact, another little trick that you may not know :
    To see the execution of a macro step, you put yourself in it and you type the key "F8". Each time you run the following command line. Its informative and very convenient.

  4. #4
    Join Date
    Nov 2009
    Posts
    36

    Re: Macro onClick copy/paste Excel

    kelfro: I do not know anything about the macro recorder; its left for later on task, may be next time!

    Katty:
    And it avoids any movement.
    Yes, its true. I had not even thought it was too simple. I stayed on his idea to copy/paste. This was one of the reason why I as hesitating to post my query here.

    Anyways, thanks for everything!

Similar Threads

  1. Replies: 5
    Last Post: 26-04-2012, 04:16 AM
  2. Need a Macro to copy data from Excel to a Application
    By NardO in forum MS Office Support
    Replies: 7
    Last Post: 12-04-2012, 10:20 PM
  3. I am not able to copy and paste data in Excel 2008
    By Apple.Mac.Rocker in forum Windows Software
    Replies: 3
    Last Post: 07-10-2009, 10:27 PM
  4. Replies: 0
    Last Post: 18-03-2009, 10:00 PM
  5. Macro- Excel to copy cell content highlighted
    By Anwar in forum Windows Software
    Replies: 3
    Last Post: 06-03-2009, 02:04 PM

Tags for this Thread

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
  •  
Page generated in 1,713,942,744.85389 seconds with 17 queries