+ Reply to Thread
Results 1 to 12 of 12

Macro – If Equal to Variable, Copy and move to Next

  1. #1
    Registered User
    Join Date
    01-10-2011
    Location
    Houston, United States
    MS-Off Ver
    Excel 2003
    Posts
    6

    Macro – If Equal to Variable, Copy and move to Next

    I have been unable to locate a solution to the following:

    A workbook with two spreadsheets titled “Sheet 1” and “Sheet 2”. In “Sheet 1”, I have a table that lists employee names, whether or not they are used on the project (Posed with a question and answered with a drop down list of “Yes” or “No”), and charge rates in columns down. I need to transfer the names of employees that are used on the project (“Yes”) to “Sheet 2” in a row format (B3:L3 for example). I need a macro that will check the first value in the specified range in “Sheet 1” of “Yes” and “No”, add the employee name to a new list if the answer is “Yes”, ignore if the answer is “no” and go through the entire range until it reaches the end.

    Any help would be much appreciated.

    Example portion of “Sheet 1”


    Column A Column B Column C

    Name Used on Project? Rate

    Alexander Yes $213.00
    MacNeill No $213.00
    Kirkland No $223.00
    Karpathy Yes $213.00

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Macro – If Equal to Variable, Copy and move to Next

    You could autofilter col B on Yes, then copy and paste the results to the other sheet.

    If you want to automate that, record a macro, and then post back if you need help cleaning it up.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Macro – If Equal to Variable, Copy and move to Next

    Hi milissadianna and welcome to the forum,

    I agree with shg from above that it would be easy to do a filter but you asked for a Macro, so here it is. Also find it in the attached file.
    Please Login or Register  to view this content.
    See the attached.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    01-10-2011
    Location
    Houston, United States
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Macro – If Equal to Variable, Copy and move to Next

    Thank you both for your responses. I should have been more clear in my first request. I have attached a spreadsheet now in hopes that it will help better explain what I am trying to achieve.

    In the tab called “2011 Rates”, in Column E there is a drop down list that the user can choose “Yes”, “No”, or “N/A”. If “Yes” is chosen I would like the “Project Title” (Column B) to be shown in Row 3 (C3:….) of the tab called “Workscope_BY_CTR”. Currently there is a drop down list in Row 3 of “Workscope_By_CTR”, I am trying to eliminate the step of having to use the drop down list. I would like to put a button in the “Workscope_By_CTR” tab that will populate the entire Row 3 with unique “Project Titles” that “Yes” has been chose for in the “2011 Rates” sheet. I would also like to avoid any issues that may arise if the user pushes the button twice.

    Thanks again!
    Attached Files Attached Files

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Macro – If Equal to Variable, Copy and move to Next

    Hi mellisadianne,
    Find the attached with a Private code (behind the worksheet) that will build your list on the second page.

    When you change any of the dropdowns of Yes/No it will cycle through and put the corrent info on your sheet two.

    Hope this gives you a way of getting your job done easier.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    01-10-2011
    Location
    Houston, United States
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Macro – If Equal to Variable, Copy and move to Next

    Thanks for the response again MarvinP. Is it possible to have you paste the code in a post? I think something may be happening in the conversion process because I’m getting some error messages about referencing external formulas and the code is appearing in a “Sheet 18”.

  7. #7
    Registered User
    Join Date
    01-10-2011
    Location
    Houston, United States
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Macro – If Equal to Variable, Copy and move to Next

    Actually, I figured it out. Thank you so much!!!! This will make things a lot easier!

  8. #8
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Macro – If Equal to Variable, Copy and move to Next

    I have no idea how it got behind sheet18 but here it is..

    This code needs to be behind Sheet 2011 Rates.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    01-10-2011
    Location
    Houston, United States
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Macro – If Equal to Variable, Copy and move to Next

    MarvinP, I really appreciate the help. I have one more question about a macro to complete the spreadsheet. I know that I should be able to figure out how to make a similar code as the previous one that you sent me, but I seem to be having trouble. Similar to the other code, in the same workbook there is a “Summary Tab” that summarizes the amount of hours allocated for each employee, I need the code to extract the name of the employee that has hours in the respective CTR sheets to the sheet titled “CTR-01” in the section titled “Personnel”. The “CTR-01” sheet currently has a drop down list, again I’m trying to eliminate a step in which the user would have to manually chose the name of the “Personnel.” The original spreadsheet has 20 CTR sheets, but I assume that once the code is written it should be easy to include in all the CTR sheets. I have attached another spreadsheet to help my inquiry make more sense.
    Attached Files Attached Files

  10. #10
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Macro – If Equal to Variable, Copy and move to Next

    Try this code:
    Please Login or Register  to view this content.
    It replaces the code from before.

  11. #11
    Registered User
    Join Date
    01-10-2011
    Location
    Houston, United States
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Macro – If Equal to Variable, Copy and move to Next

    MarvinP = I’m wondering if it would be better to have two Macros, a separate one in the “Summary” tab. Currently the macro is listing all the Employee Names in CTR-01, even the ones that don’t actually have hours. So I was wondering about having a macro that went only off of the summary tab, for example if the value in column 3 of the summary tab is greater than 0, then it lists only those names in the CTR-01 tab.

    Thanks again for the help!

  12. #12
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Macro – If Equal to Variable, Copy and move to Next

    Hi Melissadianna,
    If you record a macro and it does Range("A1").Select type of commands, it is working on the active worksheet. If you run that macro from a different sheet (the one it wasn't meant to run on) it can really mess things up.

    In my code above I was very careful to specify which worksheet was the one being used.

    My concern is that if you run a macro from a key combination like Ctrl-B you need to make sure you are on the correct sheet before letting the macro run.

    This is my concern for making more macros using the recorder and simply calling them.

    I hope that helps.

+ 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