+ Reply to Thread
Results 1 to 25 of 25

Copy range of data within sheet and rename based on cell value paste values and format

  1. #1
    Registered User
    Join Date
    06-22-2020
    Location
    Sweden
    MS-Off Ver
    O365
    Posts
    33

    Copy range of data within sheet and rename based on cell value paste values and format

    Hello everybody. I'm new to the forum and would appreciate some help. I have a code which allows me to copy sheet and rename based on cell value:

    Please Login or Register  to view this content.


    I'd like for it to only copy a specific range of data from the sheet and paste only values and format (not formulas) into the newly created sheet.

    In addition to that, if I'm trying to copy a sheet with the same name twice, I'm getting an error. Is there any possibility to add a number to the newly created sheet name in addition to the value/name (C3:C4 above) if there's already a sheet with the existing name?

    Also, for some reason, the text within my ActiveX-buttons increases in size when I click on them. Any idea why that is and how to fix it?

    Thanks in advance.
    Last edited by alansidman; 06-24-2020 at 05:22 PM.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,830

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    It would be easier to help and test possible solutions if you could attach a copy of your file. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary). See the yellow banner at the top of this page for instructions to attach a file. What specific range do you want to copy?
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    06-22-2020
    Location
    Sweden
    MS-Off Ver
    O365
    Posts
    33

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    Quote Originally Posted by Mumps1 View Post
    It would be easier to help and test possible solutions if you could attach a copy of your file. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary). See the yellow banner at the top of this page for instructions to attach a file. What specific range do you want to copy?
    Thanks for the answer, Mumps1. Please see attached file, tab "PLANNER".

    When I click the "Save" button, I want the macro to create a copy of cells A1:V35 into a new sheet named as cells C3:C4 (C4 is hidden). I want the new sheet to copy values and format, not formulas. So basically, the exact same layout in terms of colours, column/row widths etc and information but with values instead of formulas.

    If there's already a sheet with the existing name, I want the new sheet to be named as cell C3:C4 and adding a number (1, 2, 3 etc).

    For the other macros ("Clear" and "Copy" buttons), I think I've achieved what I want to achieve. But I've noticed that once I click on any of the buttons and run the macros, the text in the buttons increases in size. I don't know why this is.
    Attached Files Attached Files

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,830

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    Try:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-22-2020
    Location
    Sweden
    MS-Off Ver
    O365
    Posts
    33

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    Quote Originally Posted by Mumps1 View Post
    Try:
    Please Login or Register  to view this content.
    Thank you very much, mate. It works like a charm. I really appreciate it.

    However, I'm having troubles with my "Copy" button. The macro makes a copy of the sheet as I ask for, but the formulas seem to stop working.

    Under the tab PLANNER, if you make a choice cell C3 (Renato Vieira), then choose a drill for C12 (Piggy in the middle) and choose a value for D12 (175), some of the cells F12:T12 will return a value.
    However, if I push the button "Copy" and do the same thing in the newly created sheet, cells F12:T12 stays empty. Any idea why?

  6. #6
    Registered User
    Join Date
    06-22-2020
    Location
    Sweden
    MS-Off Ver
    O365
    Posts
    33

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    Also,
    This seems to happen with my buttons when I click on them. The text enlarges to the point where it's not visible anymore. Seems like a bug. Anyway to fix it?
    Attachment 683665

  7. #7
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,830

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    I don't see any formulas in columns F to T. When I click on any cell in these columns, the formula bar displays a zero. As far as the form button problem is concerned, I would delete them and replace them with a shape (Insert...Shapes). You can format the shapes to make them look attractive and assign the macros to them. Place the corresponding macros in a regular module instead of the sheet code module. Also your link in Post #6 doesn't work. See the yellow banner at the top for instructions on how to attach a file.

  8. #8
    Registered User
    Join Date
    06-22-2020
    Location
    Sweden
    MS-Off Ver
    O365
    Posts
    33

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    Quote Originally Posted by Mumps1 View Post
    I don't see any formulas in columns F to T. When I click on any cell in these columns, the formula bar displays a zero. As far as the form button problem is concerned, I would delete them and replace them with a shape (Insert...Shapes). You can format the shapes to make them look attractive and assign the macros to them. Place the corresponding macros in a regular module instead of the sheet code module. Also your link in Post #6 doesn't work. See the yellow banner at the top for instructions on how to attach a file.
    Thanks for the response, appreciate it. As for the formulas, that is strange. I've attached a picture showing that there're formulas in those cells. I've also uploaded the file again, maybe they're visible this time.

    As for the buttons, I'll give it a try. I think I managed to do it.

    EDIT: I'm noticing that giving the "Save" sheet the name of cells C3:C4 might be to long at times. Is there an easy way to rewrite the code so that it names the saved sheets as C3 only and if there's already an existing sheet with that particular name then just add a number starting with 1 instead? Sorry for all the questions.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Arphaxad; 06-23-2020 at 09:27 AM.

  9. #9
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,830

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    Try the attached file. I have changed the buttons to shapes and moved the macros to Module1. Everything seems to be working properly. You may want to look at the "Clear" macro. You have it set to clear the contents of AA3 and AA12. Column AA has no data in it. Perhaps the column in the code needs to be changed.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    06-22-2020
    Location
    Sweden
    MS-Off Ver
    O365
    Posts
    33

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    Quote Originally Posted by Mumps1 View Post
    Try the attached file. I have changed the buttons to shapes and moved the macros to Module1. Everything seems to be working properly. You may want to look at the "Clear" macro. You have it set to clear the contents of AA3 and AA12. Column AA has no data in it. Perhaps the column in the code needs to be changed.
    Thanks, mate. AA should be changed to AB, I'll change it.

    But the Copy button still doesn't function properly for some reason. Columns F:T don't work as they should. In the PLANNER sheet, they work properly. When you change something in column C and/or D, the same row for column F:T changes accordingly. But when I make a copy and re-do the same thing, the values in column F:T don't change. Very strange.

    Even trying a simpler COPY macro like this doesn't seem to work. So I don't think it's something wrong with the macro. For some reason column F:T don't pick up what they should when the sheet is copied

    Please Login or Register  to view this content.
    Last edited by alansidman; 06-24-2020 at 05:22 PM.

  11. #11
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,830

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    I am not experiencing the same problem. The Copy macro works properly for me, copying the formulas into the new sheets. I'm wondering if the problem is with the version of Excel that you are using. Can you try the file on a computer with an earlier version of Excel?

  12. #12
    Registered User
    Join Date
    06-22-2020
    Location
    Sweden
    MS-Off Ver
    O365
    Posts
    33

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    The problem is stupidity. I figured out what it is most likely. When the macro copies the sheet, columns F:T are still referring to the same source as the original sheet. The source lies in a separate sheet. Thus, column F:T are bound to/locked by the original sheet. I'll do some tests later and report back. Thanks for helping me out.

    Is it a simple fix to change the name of the Save sheet as I suggested above (value C3+n if there's already an existing sheet with the same name instead of C3+C4? Thanks again, mate.

  13. #13
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,830

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    Is it a simple fix to change the name of the Save sheet as I suggested above (value C3+n if there's already an existing sheet with the same name instead of C3+C4? Thanks again, mate
    .
    Could you give me a couple of examples?

  14. #14
    Registered User
    Join Date
    06-22-2020
    Location
    Sweden
    MS-Off Ver
    O365
    Posts
    33

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    Quote Originally Posted by Mumps1 View Post
    .
    Could you give me a couple of examples?
    This is the current code you wrote for me
    Please Login or Register  to view this content.


    The red part is what I want re-done. Basically, if the name Gareth Williams is written in C3, and DMC is written in C4, the saved sheet is going to be named Gareth Williams DMC. I would like it to be named Gareth Williams only instead. BUT, if there's a previous sheet named Gareth Williams I'd like it to be named Gareth Williams 1 instead and so on. Maybe just deleting the red part will do?

    The previous problem was as I suspected. I moved all the data to the PLANNER sheet and everything seems to work now. Thank you for all your help.

    EDIT:
    I managed to make it work I think by changing the line
    Please Login or Register  to view this content.


    Seems OK?
    Last edited by alansidman; 06-24-2020 at 05:21 PM.

  15. #15
    Registered User
    Join Date
    06-22-2020
    Location
    Sweden
    MS-Off Ver
    O365
    Posts
    33

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    Experiencing another problem with the Save button now that I've moved all the data from the INPUT DATA sheet to the PLANNER sheet. See attached picture. For some reason, the macro doesnt seem to copy the format in the highlighted area when I click the Save button. Also noticed that if I change the height of row 11, the saved sheet doesn't register it. I've attached the file with all the data moved to the PLANNER sheet as well.

    Sorry to be bothering you with all this. I highly appreciate your help.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Arphaxad; 06-24-2020 at 10:43 AM.

  16. #16
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,830

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    Try the attached file. I have fixed all the issues except the copying of the formatting. You are using conditional formatting for the range F3:T10 in the PLANNER sheet. The formulae you use in the conditional formatting rules refer to column AR in the PLANNER sheet. The SAVE button copies only A1:Z35. Therefore the newly created sheets don't include the data in the AR column which is necessary for the conditional formatting to work.
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    06-22-2020
    Location
    Sweden
    MS-Off Ver
    O365
    Posts
    33
    Quote Originally Posted by Mumps1 View Post
    Try the attached file. I have fixed all the issues except the copying of the formatting. You are using conditional formatting for the range F3:T10 in the PLANNER sheet. The formulae you use in the conditional formatting rules refer to column AR in the PLANNER sheet. The SAVE button copies only A1:Z35. Therefore the newly created sheets don't include the data in the AR column which is necessary for the conditional formatting to work.
    Thanks, I'll check tonight when I have access to a computer. I also thought that the problem might be connected to conditional formatting. But in the very first file you helped me with before I moved all the underlying data to the PLANNER sheet, the data was in the INPUT DATA sheet while the SAVE button was still only copying A:Z from the PLANNER sheet. But it still worked back then eventhough the underlying formulae wasn't within the columns that were copied trough the SAVE button. Any idea why it worked back then but not now? That makes me wonder if that really is the issue here. Have a look yourself in the first file in my first comments.

    Edit: is there any paste special conditional formatting code? I see it's discussed here https://stackoverflow.com/questions/28388350/copy-conditional-formatting-from-one-cell-to-another-using-vba

    But then again, this wasn't an issue in the initial file.
    Last edited by Arphaxad; 06-24-2020 at 12:11 PM.

  18. #18
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,830

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    In your original file you had the conditional formatting formulae referring to data in the INPUT DATA sheet and the formulae included a reference to the INPUT DATA sheet. So when the range was copied, the formulae still referred to the INPUT DATA sheet. Now the formulae refer to data in the PLANNER sheet which is not copied over. If you include the reference to the PLANNER sheet in the formulae, it should work.

  19. #19
    Registered User
    Join Date
    06-22-2020
    Location
    Sweden
    MS-Off Ver
    O365
    Posts
    33
    Quote Originally Posted by Mumps1 View Post
    In your original file you had the conditional formatting formulae referring to data in the INPUT DATA sheet and the formulae included a reference to the INPUT DATA sheet. So when the range was copied, the formulae still referred to the INPUT DATA sheet. Now the formulae refer to data in the PLANNER sheet which is not copied over. If you include the reference to the PLANNER sheet in the formulae, it should work.
    Checked the uploaded file, and everything seems to work perfectly. Also moved the references for the conditional formatting to the INPUT DATA sheet and the format seems to work now when I SAVE a new sheet.

    Thank you very much for your help, my friend. Your contribution is much appreciated.

    Ill try to find some good VBA tutorials on YouTube for me to start learning from. Your help has inspired me to learn more in order to be able to help myself. Thanks again.

  20. #20
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,913

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    Code Tags Added
    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  21. #21
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,830

    Re: Copy range of data within sheet and rename based on cell value paste values and format


  22. #22
    Registered User
    Join Date
    06-22-2020
    Location
    Sweden
    MS-Off Ver
    O365
    Posts
    33

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    Quote Originally Posted by Mumps1 View Post
    Thanks, mate. I will make sure to have a look.

    One more question: is it possible to lock the copied sheet so that it isn't possible to show hidden rows/columns?

  23. #23
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,830

    Re: Copy range of data within sheet and rename based on cell value paste values and format


  24. #24
    Registered User
    Join Date
    06-22-2020
    Location
    Sweden
    MS-Off Ver
    O365
    Posts
    33

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    Thanks, but I don't think that was what I was looking for. As I SAVE the PLANNER sheet, it creates a new sheet. The PLANNER sheet protection doesn't apply to the newly SAVED sheet. Is there a way for the protection and password to pass on from the PLANNER to the newly SAVED sheet as well is my question I guess.

    For example, when I use the COPY button, the protection from the initial PLANNER sheet copies over to the new COPY sheet. But when I use the SAVE button, the protection from the PLANNER sheet doesn't copy over to the new SAVE sheet.

    The difference between the two (COPY and SAVE) is that the former copies everything including formulaes, while the latter pastes special (values and format).

    EDIT
    I think I managed to solve my problem. I added the highlighted row to the code
    Please Login or Register  to view this content.
    Last edited by Arphaxad; 06-26-2020 at 07:12 AM.

  25. #25
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,830

    Re: Copy range of data within sheet and rename based on cell value paste values and format

    Looks good.

+ 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. [SOLVED] VB Code to copy and paste range to certain sheet based on cell Value
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-22-2019, 03:38 PM
  2. Replies: 2
    Last Post: 02-06-2016, 10:19 AM
  3. [SOLVED] Copy Paste a Range of Values from a Different Sheet Based on Value Entered in Cell
    By hamidxa in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-13-2015, 04:53 PM
  4. 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
  5. [SOLVED] Copy and Paste Range of Cells based on # of cell values in Column A
    By bwaite87 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-17-2014, 05:51 PM
  6. Replies: 3
    Last Post: 02-21-2013, 12:48 AM
  7. Finding a named range based on cell value and copy/paste to same sheet?
    By Simon Lloyd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2006, 06:25 PM

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