+ Reply to Thread
Results 1 to 24 of 24

Excel Macro Loops, Copy, Paste

  1. #1
    Registered User
    Join Date
    03-17-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2013
    Posts
    34

    Exclamation Excel Macro Loops, Copy, Paste

    Hi I need your help, I'll try and make this as clear as I can.

    So I have two sheets, Sheet1 Sheet1.JPG and Sheet 2 Sheet2.JPG. For each item there is a corresponding ID.
    Apple is 1, Orange is 2 and so on and so forth.

    What I need to do is to create a macro that will go through the ID in Column A - Sheet 1 and then paste only the matching ID's in Column B - Sheet 2.

    So for example on Sheet 1 - Column A, ID no. 1, the Item is Apple, the code will go through the ID column and read that for the ID no. 1 the item is Apple,

    and then it will paste the Item "Apple" beside the ID no. 1 in Sheet 2 because the ID 1 is for the item Apple.

    I hope that was clear.

    Thank You

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Excel Macro Loops, Copy, Paste

    "An attached book is worth millions of words". Not a lot we can do with a picture

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Excel Macro Loops, Copy, Paste

    In B2 cell of Sheet2
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Drag it down...


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Excel Macro Loops, Copy, Paste

    myownworld,

    You are posting pictures/graphics. This means that if this was a problem where one needed to use your data, anyone trying to help you would have to enter the data manually. That makes no sense.

    To get the most precise answer, it is best to upload/attach a sample workbook (sensitive data scrubbed/removed/changed) that contains an example of your raw data on one worksheet, and on another worksheet your desired results.

    The structure and data types of the sample workbook must exactly duplicate the real workbook. Include a clear and explicit explanation of your requirements.

    To attach your workbook, scroll down and click on the Go Advanced button, then scroll down and click on the Manage Attachments button.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  5. #5
    Registered User
    Join Date
    03-17-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2013
    Posts
    34

    Re: Excel Macro Loops, Copy, Paste

    Ok here's the uploaded sample workbook.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Excel Macro Loops, Copy, Paste

    myownworld,
    I would not recommend using a code for this simple task which could be easily done by Excel's VLookup or match and index functions, but if you insist you want a code, see attached
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    03-17-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2013
    Posts
    34

    Re: Excel Macro Loops, Copy, Paste

    Wow. You guys reply fast. This really helped.

    Thank You so much!

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Excel Macro Loops, Copy, Paste

    myownworld,
    You are welcome!

  9. #9
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Excel Macro Loops, Copy, Paste

    myownworld,

    Thanks for the workbook.

    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    Please Login or Register  to view this content.
    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

    Then run the GetItem macro.

  10. #10
    Registered User
    Join Date
    03-17-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2013
    Posts
    34

    Re: Excel Macro Loops, Copy, Paste

    I attached another sample workbook, i need to do almost the same thing here, but i'm having a harder time here.

    The only difference in this second sample workbook is that there's another column added (Item number) and this time this is the column that needs to be copied and pasted and that the ID repeats for every item and it serves as a counter for the items.

    Its the same condition with the first one, it needs to go through the ID and paste the matching id to the second sheet without the spaces too.

    Thank you
    Attached Files Attached Files
    Last edited by myownworld; 04-04-2013 at 12:35 PM.

  11. #11
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Excel Macro Loops, Copy, Paste

    myownworld,
    Once a thread has been closed and if you have any new request, you need to post it as a new thread, otherwise, it will be open until eternity.
    See attached.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    03-17-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2013
    Posts
    34

    Re: Excel Macro Loops, Copy, Paste

    ok thank you AB33 i'll just post a new thread regarding this new inquiry

  13. #13
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Excel Macro Loops, Copy, Paste

    myownworld,
    Did not you my last attached answer your request?

  14. #14
    Registered User
    Join Date
    03-17-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2013
    Posts
    34

    Re: Excel Macro Loops, Copy, Paste

    it's not exactly what i was looking for, cause when i tried to run the macro what happened was it kind of doubled the items, if you look at sheet 3 the apple count was only 30 then when i run the macro the count of the apple became 132, the same with the other items.

    and the for the other items they start with a different item number not all of it starts with 10 and ends with 39, that's only for the apple, there's a different item number for the items.

  15. #15
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Excel Macro Loops, Copy, Paste

    myownworld,
    Sorry!
    I did not see you had a gap on your data, so my current region only picked up values up to row 31. I will correct it in a minute, but need to ask you again. You want to return the value from sheet3, column C in to sheet 4 ,column C when match is found. Is this right?

  16. #16
    Registered User
    Join Date
    03-17-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2013
    Posts
    34

    Exclamation Re: Excel Macro Loops, Copy, Paste

    Yes that's right, I attached another workbook and added another tab so you can check out what it should look life after.

    Thank You so much!
    Attached Files Attached Files

  17. #17
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Excel Macro Loops, Copy, Paste

    Try the attached.
    Attached Files Attached Files
    Last edited by AB33; 04-05-2013 at 11:20 AM.

  18. #18
    Registered User
    Join Date
    03-17-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2013
    Posts
    34

    Re: Excel Macro Loops, Copy, Paste

    Yeeeeess! That's how I want it :D Just one more though, I re-run the macro again but how come the banana item was cut down to one, the other 8 got deleted?

  19. #19
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Excel Macro Loops, Copy, Paste

    See attached abve

  20. #20
    Registered User
    Join Date
    03-17-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2013
    Posts
    34

    Re: Excel Macro Loops, Copy, Paste

    i did, what i did was i cleared the items on Sheet 4 - Column C and then I re-run the macro and then I noticed that the last row became 111 instead of 119. the other 8 banana item got deleted..

  21. #21
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Excel Macro Loops, Copy, Paste

    Myownworld,
    I know what the issue is. The loop had stopped at row 19 in sheet 3, so the code did not look beyond it. See the attached works better.
    Attached Files Attached Files

  22. #22
    Registered User
    Join Date
    03-17-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2013
    Posts
    34

    Re: Excel Macro Loops, Copy, Paste

    Got it now, thank you so much AB33!

  23. #23
    Registered User
    Join Date
    03-17-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2013
    Posts
    34

    Re: Excel Macro Loops, Copy, Paste

    Got it now, thank you so much AB33!

  24. #24
    Registered User
    Join Date
    03-17-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2013
    Posts
    34

    Re: Excel Macro Loops, Copy, Paste

    Hi again, i know i already marked this thread as solved then i marked it again as unsolved cause i can't edit the code you gave, it's just too advance for me

    could you please help me again, i attached the workbook, it's exactly how it looks like on the original one that i'm working on, i should've done this the first time sorry, i hope you could help me again thanks so much
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1