+ Reply to Thread
Results 1 to 19 of 19

Copy Row/Rename based on Cell Value

  1. #1
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Copy Row/Rename based on Cell Value

    Hello Forum Gurus!

    Need help with some VBA or macro to basically copy the content of a cell and rename with the addition of the value of other cells (X in Category field). Each row will have AT LEAST 1 X, but will not likely have ALL categories marked X.

    Ex. CategoryA CategoryB
    cell name1 X
    cell name2 X X

    Desired results:

    cell name1_CategoryA
    cell name2_CategoryA
    cell name2_CategoryB


    Thanks for any/all help!
    Betsy

  2. #2
    Forum Contributor
    Join Date
    06-12-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    167

    Re: Copy Row/Rename based on Cell Value

    Just to clarify these X's will be names or text strings.

    Or will they be literally X's and you want the heading to be added

  3. #3
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Re: Copy Row/Rename based on Cell Value

    Hi Dougman824, thanks for responding!

    The "x" only indicates that the category name should be added to the original name. So it's the category/name heading that should tagged onto the original name,
    but only when there is an X in the cell under that category.

    Make sense?
    betsy

    The formatting on the example didn't work right so I'm attaching a sheet to show it more clearly.
    Attached Files Attached Files
    Last edited by Betsy Simpkins; 07-10-2017 at 06:11 PM. Reason: add attachment

  4. #4
    Forum Contributor
    Join Date
    06-12-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    167

    Re: Copy Row/Rename based on Cell Value

    Its acting as a check box basically saying that this cell name does in fact have this category

  5. #5
    Forum Contributor
    Join Date
    06-12-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    167

    Re: Copy Row/Rename based on Cell Value

    Also where would you like these news names placed

  6. #6
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Re: Copy Row/Rename based on Cell Value

    Just after the original name separated by an underscore if that's possible.

    THANKS!

  7. #7
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Re: Copy Row/Rename based on Cell Value

    You got it!

  8. #8
    Forum Contributor
    Join Date
    06-12-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    167

    Re: Copy Row/Rename based on Cell Value

    So for example if cell a2 is the original name then all of the cells to the right are the categories you would want the name to be replaced by the new name?

    And if for example you had 2 x's then it would be Originalcellname_x1_x2?

  9. #9
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Re: Copy Row/Rename based on Cell Value

    Sort of. Each new name needs to be it's own row so that they can be sorted etc. So it should look something like this if the original name has an X in two categories:

    original name_newcategoryA
    original name_newcategoryB

    Obviously if there is only 1 category with an X then that row would only be copied/renamed once with the original name+new category.

  10. #10
    Forum Contributor
    Join Date
    06-12-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    167

    Re: Copy Row/Rename based on Cell Value

    Can I generate a list on a new sheet of all of the new names?

    Or does it require that it is on the same sheet? (if so can you post a small sample that I can look at with the start and end goal so I can see exactly what you want)

  11. #11
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Re: Copy Row/Rename based on Cell Value

    New sheet is fine. I did upload an example though...guess I attached it to one of the messages above...can you see it?

  12. #12
    Forum Contributor
    Join Date
    06-12-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    167

    Re: Copy Row/Rename based on Cell Value

    Based on what I know this will check the cells assuming the headers (categories) are in row 1 and the names are in column A. let me know if more help is needed

    It also puts the new names on sheet 2

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Re: Copy Row/Rename based on Cell Value

    I get a subscript out of range error. Not sure why. The rows should contain the original cell name in A2 and the columns are the various categories in B1, and the X are in B2, etc....but I think I can switch the code around...if I can get it to work the way you have it. But not sure what to do about that error.

  14. #14
    Forum Contributor
    Join Date
    06-12-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    167

    Re: Copy Row/Rename based on Cell Value

    Most likely the issue is the worksheets name if I had to guess. Where it has sheet2 you will need to change that to the desired worksheet name for where the names will be stored.

    Also just to make this more dynamic and not run 10000 times, is there always the same amount of rows and columns?

  15. #15
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Re: Copy Row/Rename based on Cell Value

    No, there won't always be the same number of rows because some will have X's in ALL categories while others won't and that will change every month.

    Side note...it is aggregating ALL the new names onto the original name with an underscore for each category...but they need to each be in their own rows...not all in the same name.

    So if a record has 2 x's, it should have 2 corresponding rows....not one with two names. So it's not really "total cell names combined" but rather cell names combined for EACH
    original name + new name....then a new row for the next.

    Are you able to fix that?

  16. #16
    Forum Contributor
    Join Date
    06-12-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    167

    Re: Copy Row/Rename based on Cell Value

    Ok do fix this just get rid of the line that is:

    Please Login or Register  to view this content.
    Also if there will never be a blank row in row 1 I can set this to run on as many times as there are rows of data.

    The same could be done if there are no blanks in the column headings as well.

    You may also want to add at the very start the indicated line:

    Please Login or Register  to view this content.
    Last edited by dougman824; 07-11-2017 at 10:58 AM. Reason: extra add

  17. #17
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Re: Copy Row/Rename based on Cell Value

    This is GREAT! Correct.....there will never be a blank in row 1. As far as columns, there won't be a blank in B, but every month the number of columns will change so one month there could be only 3 columns while the next month there could be 10. I'm not sure that qualifies as "blanks" though. So yeah, running as many times as there are rows and columns would be great since that could ensure I don't miss any data.

    I SUPER appreciate you and all that you do on these forums. For newbies like me, it just makes such a difference and I am very thankful

    Betsy

  18. #18
    Forum Contributor
    Join Date
    06-12-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    167

    Re: Copy Row/Rename based on Cell Value

    I changed the code to make run the least amount of times possible. (Do not if there is a blank cell in row A in the middle of the data it will stop running. For example if you don't have a NF000x in the name column. The code finds that blank to be the end)

    I added comments on what is different from what I have sent before.

    Please Login or Register  to view this content.
    Also if this solves the thread please mark it as solved at the top under thread tools and feel free to add reputation if you feel I have been helpful

    If you need more help let me know.

  19. #19
    Registered User
    Join Date
    12-07-2016
    Location
    Oregon, USA
    MS-Off Ver
    2016
    Posts
    33

    Re: Copy Row/Rename based on Cell Value

    YAY! This is perfect! I'll try it out tomorrow with some real data and I'll let you know if I have any problems. I'll mark it SOLVED though...since you DID

    THANKS!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copy paste and rename folder based on Cell values
    By BrettRogersUK in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-28-2014, 04:54 AM
  2. Replies: 0
    Last Post: 06-28-2014, 02:26 PM
  3. Macro - Copy sheet and rename based on cell value
    By Nick.123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-15-2013, 04:23 AM
  4. macro to copy a range of worksheets based on cell entry and rename specific sheets
    By Lbischoff in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-14-2012, 12:13 PM
  5. [SOLVED] Copy a sheet (from template) to a new sheet, and rename (based on cell value)
    By Siglen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-30-2012, 10:19 AM
  6. Copy worksheet and rename based on cell range
    By jpruffle in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-08-2011, 06:53 AM
  7. Automated worksheet copy, rename based on cell results
    By humboldtguy in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-01-2009, 01:11 AM

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