+ Reply to Thread
Results 1 to 14 of 14

Copy and Paste Macro

  1. #1
    Registered User
    Join Date
    11-27-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2003
    Posts
    17

    Copy and Paste Macro

    Hello Everyone. I am a VBA newbie and need help with a particular issue.

    For work I need to design a macro that can help calculate overhead fees.

    I download a raw report and I need to copy a particular secition from the report and paste it onto another page where I will do my calculations.

    A simple example to clarify what I need to do is lets say I have a spread sheet with three columns (see attachment). With the first column as fruits, second column as countries and third column as numbers.


    apple india 343
    oranges mexico 324
    bananas china 765
    peaches canada 8678
    cherries canada 4234
    mangoes canada 545
    kiwi canada 2313
    apples india 13
    strawberries japan 4545


    I need a macro that would copy the section containing the fruits country and number for the entire section when the country is canada. Basically a macro that will stop at canada, select from peaches, down to the number 2313 and paste this box onto a another page.

    Then I need my macro to caluclate 51% of the numbers of this secition.

    This is a simple example of what I need to do, basically when I download the raw data there will be a spreadsheet full of ledger details, however the section I need to copy to calculate overhead charges will always have the same word "F12BAPRS" in one of the colums. I just need to copy this section and multiple the amounts by 51% to calculate overhead charges.

    If anyone can assist me with my issue I would be more than grateful!
    Attached Files Attached Files
    Last edited by dinesababu1; 07-09-2012 at 11:59 PM.

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

    Re: Copy and Paste Macro

    Why dont you attach a file which has the same format as your original file?

    It will be easier for you to replicate the solution in your original file.
    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]

  3. #3
    Registered User
    Join Date
    11-27-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Copy and Paste Macro

    Its okay, I can modify the code so it can be used in the original file. Do you know how to do what I asked with the example I have given?

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

    Re: Copy and Paste Macro

    OK, if you can adjust it, then fine

    How would "Canada" be specified? Will the user be entering it in a input box? Or will it be present in a particular cell?

  5. #5
    Registered User
    Join Date
    11-27-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Copy and Paste Macro

    canada will be in the cells of a particular column

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

    Re: Copy and Paste Macro

    Which cells? The macro needs to know this.

  7. #7
    Registered User
    Join Date
    11-27-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Copy and Paste Macro

    Can we use my example from the other thread?

    Hey Guys

    I am a VBA rookie, and I can use help designing a Macro for work. There are a few steps I will need to accomplish so I will just take one step at a time.

    First I need to be able to copy a particular part of a report and paste it onto another page.

    In the attachment I need to copy the section where in Column K it says Canada. I will need to copy only Columns G to M for this section and for all the rows where Canada is in column K ( I have highlighted in light blue the section I need copied).

    So essentially I need a macro to search for Canada in Column K and to create a selection box from K to M for only where there is Canada in column K. I will then need to paste this onto the another tab.

    I have attached the document, any assistance is greatly appreciated, please let me know if I should clarify anything I have said.
    Attached Files Attached Files

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

    Re: Copy and Paste Macro

    There were no headers in the first row, so i inserted a blank row.

    Try this code
    Please Login or Register  to view this content.


    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

  9. #9
    Registered User
    Join Date
    11-27-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Copy and Paste Macro

    Wow, Thanks so much it works very well.

    I was wondering can this code be modified so it takes two criteria? What If I want to copy a section that has "Canada" in column K AND "1550" in column G.

    I ask because in my report I will have other sections that has Canada in K but not 1550 in Column G and I do not need to copy these sections.

    Thanks for all your help.

  10. #10
    Registered User
    Join Date
    11-27-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Copy and Paste Macro

    Actually I was able to figure that on my own. All I had to do was include an "AND" function.

    Now I am wondering how do I paste the copied box into a particular section in my "paste" worksheet?

    Lets say I want the copied box to be pasted starting at speficially B10? So we can no longer use the "Range("A" & Rows.Count).End(xlUp).Offset(1, 0)" part of your code, how can I tweak this so it will be pasted starting at a particular cell of my choosing.

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

    Re: Copy and Paste Macro

    The code above copies row by row, so you have to use the offset part of the code.

    What you can do is, put a dummy value in A9 and automatically the data will pour in from row 10 onwards.

  12. #12
    Registered User
    Join Date
    11-27-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Copy and Paste Macro

    Hey Arlu

    Actually that would not quite work. Though in the example I used the "paste" worksheet is blank. In actuality the worksheet I use will have particular sections I will need to paste in order to calculate the OH charges. I have attached the excel file of where I actually need the values pasted. I need the section that the macro you have written will paste exactly in the cells A11:G25 section in the worksheet "Payroll OH Alloc Calc June" worksheet.

    Basically paste the copied section under where it says "COPY AND PASTE TO CLEAN COPY OF RAW DATA".

    Thank you!!


    P.S.
    There will more sections I need copied and pasted on other sections in the worksheet "Payroll OH Alloc Calc June", however I am sure I can figure out how to modify your codes to do that.
    Attached Files Attached Files

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

    Re: Copy and Paste Macro

    Try this
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    11-27-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Copy and Paste Macro

    Thank you so much. The macro works perfectly. I am going to have to review it thoroughly in order to really understand how it works. But your help is greatly appreciated and will make work a little easier for my department. Thanks again and if there is any feedback or comments you would need me to leave please let me know.

+ 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