Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 09-12-2009
Member
 
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.
Reply With Quote
  #2  
Old 09-12-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
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
Reply With Quote
  #3  
Old 09-12-2009
Member
 
Join Date: May 2008
Posts: 2,008
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.
Reply With Quote
  #4  
Old 09-12-2009
Member
 
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:
Quote:
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!
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Macro onClick copy/paste Excel"
Thread Thread Starter Forum Replies Last Post
I cannot do Copy and Paste or Paste Special between Excel Workbooks Acca-OR Windows Software 5 26-04-2012 04:16 AM
Need a Macro to copy data from Excel to a Application NardO MS Office Support 7 12-04-2012 10:20 PM
I am not able to copy and paste data in Excel 2008 Apple.Mac.Rocker Windows Software 3 07-10-2009 10:27 PM
Copy Text from One Cell to Another in Microsoft Excel without copy & paste Computer_Freak Tips & Tweaks 0 18-03-2009 10:00 PM
Macro- Excel to copy cell content highlighted Anwar Windows Software 3 06-03-2009 02:04 PM


All times are GMT +5.5. The time now is 02:50 PM.