+ Reply to Thread
Results 1 to 6 of 6

Code to copy and paste row from one excel sheet to another, based on criteria

  1. #1
    Registered User
    Join Date
    01-23-2013
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    3

    Code to copy and paste row from one excel sheet to another, based on criteria

    Hi,

    I am new to this forum, so please excuse me if I don't do this right!

    I have two spreadsheets of data, so called "Sheet 1" and "Sheet 2". In Sheet 2, users will be able to type into a table the detail of their sales opportunity. E.g. A1 would be customer, B1 would be potential and so on. This sheet has 7 columns of data.

    Another person will then come in and look through the opportunities, and when they find one they would like to work on, I want them to type Qualified into the last cell. When they press a button to refresh, the coding will then take any opportunities with Qualified in the last cell, and paste them into the next available row on sheet 1.

    I have tried several codes linked to similar issues but I can't get them to work.

    I would be grateful for any support you are able to provide.
    CamSeren
    Last edited by CamSeren; 01-24-2013 at 06:05 AM. Reason: Formatting lost spacing

  2. #2
    Registered User
    Join Date
    01-18-2013
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Code to copy and paste row from one excel sheet to another, based on criteria

    Hi CamSeren,

    I learned how to program macros on excel by recording a macro with the actions I needed, and modify it according to my needs. Having some basic programming knowledge and understanding helps a lot.

    Trying to help you, but also to provide you a way of learning, I did exactly this thing: I recorded a macro performing what you needed, then modified the code, and you can find it below.

    The code works only once, and this is what it does:
    - it finds the first occurance of the word "Qualified" in column G
    - selects and cuts the line the word is in
    - switches to Sheet1 and selects first free cell in column A
    - pastes the cut line
    - switches back to Sheet2 and deletes the (empty) line

    Certainly, once you insert the Refresh button that you mentioned, you can add a loop in the code behind it, so that it calls repeatedly the macro. The macro is not finished, e.g. has no provision of what will happen if searched string is not found. But I guess that if you're experienced enough to insert a working button, you can handle it.

    Good luck

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-23-2013
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Code to copy and paste row from one excel sheet to another, based on criteria

    Hi jbg. Thank you for this, and the tip about recording a macro first. It is definitely a new learning curve for me.

    I have inputted the code but it keeps coming up with the error message: 'Object variable or with block variable not set'. Apologies if I am confusing the situation!

    Thank you for the quick response.
    CamSeren

  4. #4
    Registered User
    Join Date
    01-18-2013
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Code to copy and paste row from one excel sheet to another, based on criteria

    You can debug the subroutine (Press F8 to execute each line of code) to check which is the undefined variable. Check the Sheets names would be my first suggestion. If they are correct (according to the code, Sheet1 and Sheet2), then debug, else, change the sheet names in the code.

  5. #5
    Registered User
    Join Date
    01-23-2013
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Code to copy and paste row from one excel sheet to another, based on criteria

    Hi jbg with a few tweaks this now works great. Thank you very much for your help

  6. #6
    Registered User
    Join Date
    01-18-2013
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Code to copy and paste row from one excel sheet to another, based on criteria

    You're welcome

+ 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