+ Reply to Thread
Results 1 to 9 of 9

Macro That Automatically Copies Row from Sheet 1 into Sheet 2 Based on Info in that Row

  1. #1
    Registered User
    Join Date
    05-29-2011
    Location
    Hawley, PA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Macro That Automatically Copies Row from Sheet 1 into Sheet 2 Based on Info in that Row

    Howdy Excel Forum!

    Ha, I apologize off the top for my wordy title... but I've been struggling to figure out how to automatically copy a row of information from Sheet 1 into Sheet 2 if one of the columns in that row contains the text "OKTF." From what I've read, I think I might have to use a macro to accomplish this--and that terrifies me! I think it will be easier to understand if you can see the Excel file, so I've attached it to this post:

    WorkListRevised.xlsx

    Basically, if (and only if) Column H contains the text "OKTF," I'd like to copy that row automatically to the second sheet ("2nd Visit tracker"). If it's at all possible, I'd like to have Excel copy only Column D (and relocate it to Column A on the second sheet), Column C (and relocate it to column C on the second sheet), and Column B (and relocate it to column D on the second sheet). If that complicated setup wouldn't be possible, I'd be happy just to have the entire row copied.

    Now my one concern is that I'd need the macro to not apply to Columns B and E on Sheet 2 (since the information in these columns would be added afterward). In my previous experience with macros, I've noticed that they tend to re-populate the sheets each time you run it--so I worry that once the rows are copied from Sheet 1 to Sheet 2 and the additional information is manually entered into the second sheet, the macro will re-populate the list and throw things out of order. Is there any way to force the macro not to touch the rows it has already copied?

    I would be enormously grateful for any help you guys could provide... or even any advice you could offer for how I could achieve my goals here of isolating just the rows with a column containing the text "OKTF."

    Thank you very much!!

    Michael

  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: Macro That Automatically Copies Row from Sheet 1 into Sheet 2 Based on Info in that Ro

    A few questions -

    Do you want the copy paste to happen after you have updated the data in the sheet or instantly as soon as OTKF is entered in column H?

    Also, once data is copied from Sheet 1 to Sheet 2, and then you make changes to Sheet 1, you will want this data to be copied as well. So there are 2 ways to do this -
    1. Clear Sheet 2 and re-load from row 2 of Sheet 1.
    2. Have a separate column in Sheet 1 which has an identifier to tell the macro that the row has been copied, the macro then checks for rows which do no have the identifier and copies those records only. (You can format the column using webdings font which puts in a tick mark into the box if you type alphabet "a".)
    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
    05-29-2011
    Location
    Hawley, PA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Macro That Automatically Copies Row from Sheet 1 into Sheet 2 Based on Info in that Ro

    Hi Arlette,

    Thank you for your response! Regarding your first question: As long as the data is copied onto the second sheet, I would be fine with it either copying instantly or if I had to manually run something to make the copy happen.

    I'm a little confused about how to accomplish what you've described, however. For example, how do I re-load Row 2 of Sheet 1 to cause it to copy the new "OKTF" entries onto Sheet 2 (without thing the entries it had previously copied onto Sheet 2)? I would also be willing to add a column to Sheet 1 that had an indicator (e.g., a box with a tick mark) to stop Excel from re-copying those rows. Ha, sadly though, I have no idea how to accomplish that.

    Do you think it would be possible to make this work without having to figure out how to write up a macro?

    Thank you, again, for your help!

    Michael

  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: Macro That Automatically Copies Row from Sheet 1 into Sheet 2 Based on Info in that Ro

    There may be some lil complex formulae that can do this for you, but i am not very well versed with them.....i can help you with the macro.

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

    Re: Macro That Automatically Copies Row from Sheet 1 into Sheet 2 Based on Info in that Ro

    Try this code
    Please Login or Register  to view this content.
    I have attached your file after inserting the column.

    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 View | Macros
    Select a macro in the list, and click the Run button
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    05-29-2011
    Location
    Hawley, PA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Macro That Automatically Copies Row from Sheet 1 into Sheet 2 Based on Info in that Ro

    Arlette,

    Thank you for all of your help! I seem to be running into a problem, however, and can't get the macro to actually produce output on the second sheet. For example, on the sheet you attached, I *am* able to run the macro. However, if I add another check ("a") in Column J and run the macro, it doesn't add that information to the second sheet. Do you know what I might be doing wrong?

    Thank you!!!!!

    Michael

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

    Re: Macro That Automatically Copies Row from Sheet 1 into Sheet 2 Based on Info in that Ro

    I need to explain something here.

    The macro will add the "a" which creates the tick mark once a row has been copied. You do not need to enter it yourself. If the row has a "a" or tick mark it means the row has been copied.

  8. #8
    Registered User
    Join Date
    05-29-2011
    Location
    Hawley, PA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Macro That Automatically Copies Row from Sheet 1 into Sheet 2 Based on Info in that Ro

    Oy, my bad. This is phenomenal!! You are surely some kind of wizard. Thank you so much for all of your help!!!

    Michael

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

    Re: Macro That Automatically Copies Row from Sheet 1 into Sheet 2 Based on Info in that Ro

    Am glad its solved.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

+ 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