+ Reply to Thread
Results 1 to 29 of 29

using a macro to copy a worksheet but change formulas cell references

  1. #1
    Forum Contributor
    Join Date
    02-07-2016
    Location
    England
    MS-Off Ver
    2019
    Posts
    270

    using a macro to copy a worksheet but change formulas cell references

    Hello excel forum!

    I was wondering if it was possible to create a macro that copies a workshee but changes the formulas cell reference. For example moves the cell reference from cell A:1 to A:12 then when run again from A:12 to A:23 etc etc.

    Please let me know if you would like me to post a template
    Thanks
    James

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: using a macro to copy a worksheet but change formulas cell references

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Contributor
    Join Date
    02-07-2016
    Location
    England
    MS-Off Ver
    2019
    Posts
    270

    Re: using a macro to copy a worksheet but change formulas cell references

    Im not sure why but i am unable to attach a file.

    When the paperclip icon is clicked nothing happens.

  4. #4
    Forum Contributor
    Join Date
    02-07-2016
    Location
    England
    MS-Off Ver
    2019
    Posts
    270

    Re: using a macro to copy a worksheet but change formulas cell references

    Please see attached.

    I am looking to copy the last worksheet named Student 3 and then move the copy sheet to the end and then i want to move the row values (in the formulas) in the freezed pane down by 5, for example if it was B:1 before it was copied they would change to B:6 and the row values in the formulas not in the freeze panes i would like them to move down by 11, for example if the row in the formula was B:11 before it was copied i would like it to change to B:22.

    Thanks i hope this makes sense.

    I look forward to your reply.
    Last edited by Jamidd1; 02-16-2016 at 04:31 PM.

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: using a macro to copy a worksheet but change formulas cell references

    Hi Jamidd,

    The code generates a name conflict with sheet for Student 5 - we need to update the names also when we add a new sheet - I need some guidance on that! But, this code will make a new sheet - but, before another is made we'll have to deal with the name assignments

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    02-07-2016
    Location
    England
    MS-Off Ver
    2019
    Posts
    270

    Re: using a macro to copy a worksheet but change formulas cell references

    Thank you for your help.

    Can I not just rename the sheet nyself once it is created a bit annoying but wouldn't be a problem.

    Or do you mean something else?

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: using a macro to copy a worksheet but change formulas cell references

    Hi Jamidd,

    The workbook names get duplicated with the creation of the new sheet and by the second new sheet there are conflicts - I suggest using this code I found on datawright.com

    Please Login or Register  to view this content.
    If we could also delete the remaining StudentLinks, then the problem would resolve.

    I've come up with this so far - but it doesn't seem satisfactory:

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    02-07-2016
    Location
    England
    MS-Off Ver
    2019
    Posts
    270

    Re: using a macro to copy a worksheet but change formulas cell references

    Hello Thank you for your reply!

    So what do each of these codes do exactly?

  9. #9
    Forum Contributor
    Join Date
    02-07-2016
    Location
    England
    MS-Off Ver
    2019
    Posts
    270

    Re: using a macro to copy a worksheet but change formulas cell references

    I have just tried the last code you entered it does copy the worksheet a treat but it does not do the main bit of changing the row values in the formulas!

    Can i ask what the first code you posted in your last message was for?

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: using a macro to copy a worksheet but change formulas cell references

    It does the "main bit" for me! Are your sheet names different than in the sample? Here is the commented code:

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    02-07-2016
    Location
    England
    MS-Off Ver
    2019
    Posts
    270

    Re: using a macro to copy a worksheet but change formulas cell references

    Wow! thats amazing thank you!

    Yes the names will change, will this be a problem?

    Would you be able to highlight which bits i would be able to change an adapt to use for other workbooks? I have another workbook very similar just with different tab names and the cell may be different references but the same jump in distant i need when a new sheet is create. it would be nice to have a go at adapting this myself

    I can kind of see certain bits but not all!
    Last edited by Jamidd1; 02-16-2016 at 01:33 PM.

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: using a macro to copy a worksheet but change formulas cell references

    Changing the names will not only obviate this code but will totally foul up your named ranges - how will the names change? The salient code? Let me know how the names change

    *The code that parses the formula is the nitty gritty of this routine

  13. #13
    Forum Contributor
    Join Date
    02-07-2016
    Location
    England
    MS-Off Ver
    2019
    Posts
    270

    Re: using a macro to copy a worksheet but change formulas cell references

    As is student name may change to john smith. They are not going to be student 1 etc.

    I already have another macro that names my tab from whats in cell A:1 of the worksheet.

    The tabs are all the same in terms of the student details tab and the exam tab etc but the student tabs names will change.

    So i would not be able to adapt this code myself?

  14. #14
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: using a macro to copy a worksheet but change formulas cell references

    You'd better send me a new sample so I can, maybe, figure it out The code now is depending on the number in the name

  15. #15
    Forum Contributor
    Join Date
    02-07-2016
    Location
    England
    MS-Off Ver
    2019
    Posts
    270

    Re: using a macro to copy a worksheet but change formulas cell references

    Ahh i see that makes sense! Ok it may take me till the morning ill have to take data out etc.

    Thank you for all your help so far!

  16. #16
    Forum Contributor
    Join Date
    02-07-2016
    Location
    England
    MS-Off Ver
    2019
    Posts
    270

    Re: using a macro to copy a worksheet but change formulas cell references

    PS. Maybe we need it to just give it a default name.

  17. #17
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: using a macro to copy a worksheet but change formulas cell references

    Okay -hasta manana!

  18. #18
    Forum Contributor
    Join Date
    02-07-2016
    Location
    England
    MS-Off Ver
    2019
    Posts
    270

    Re: using a macro to copy a worksheet but change formulas cell references

    HelLo!
    I have managed to sort out the spreadsheet for you! i hope everything you need is on the workbook. It is very similar to the last one with only some slight changes.

    Please see Attached.

    Thanks

    I really do appreciate your help!
    Last edited by Jamidd1; 02-17-2016 at 02:18 PM.

  19. #19
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: using a macro to copy a worksheet but change formulas cell references

    This works after I deleted the StudentLink:

    Please Login or Register  to view this content.

  20. #20
    Forum Contributor
    Join Date
    02-07-2016
    Location
    England
    MS-Off Ver
    2019
    Posts
    270

    Re: using a macro to copy a worksheet but change formulas cell references

    Thank you so much this is amazing!! is it better to copy this code into its own module or onto the whole workbook or just one sheet?

    I also have another question regarding the copy rows macro you helped me with before if you dont mind helping?

  21. #21
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: using a macro to copy a worksheet but change formulas cell references

    You're welcome!

    Any standard module will do but don't use a class module (Sheet or Book).

    (If you squelch those hyperlinks, we can write a double-click event to get the sheets.)

    What's your question?
    Last edited by xladept; 02-17-2016 at 01:19 PM.

  22. #22
    Forum Contributor
    Join Date
    02-07-2016
    Location
    England
    MS-Off Ver
    2019
    Posts
    270

    Re: using a macro to copy a worksheet but change formulas cell references

    Sweet!
    and which hyperlinks are you talking about?

  23. #23
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: using a macro to copy a worksheet but change formulas cell references

    I added a line since you're agreeable:

    Please Login or Register  to view this content.

  24. #24
    Forum Contributor
    Join Date
    02-07-2016
    Location
    England
    MS-Off Ver
    2019
    Posts
    270

    Re: using a macro to copy a worksheet but change formulas cell references

    I dont understand what this line does?

    You havernt explained what i need to do with the hyperlinks haha!

  25. #25
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: using a macro to copy a worksheet but change formulas cell references

    Hey Jamidd,

    It does exactly what it says - it deletes all the hyperlinks in the new sheet

  26. #26
    Forum Contributor
    Join Date
    02-07-2016
    Location
    England
    MS-Off Ver
    2019
    Posts
    270

    Re: using a macro to copy a worksheet but change formulas cell references

    Oooo i didnt realise there was any hyperlinks in the new sheets!!

  27. #27
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: using a macro to copy a worksheet but change formulas cell references

    Yeah, that was the glitch after I got rid of the student links and that's why I wrote this bypass code:

    Please Login or Register  to view this content.

  28. #28
    Forum Contributor
    Join Date
    02-07-2016
    Location
    England
    MS-Off Ver
    2019
    Posts
    270

    Re: using a macro to copy a worksheet but change formulas cell references

    oo i see i see! So i guess this is solved then!!!

  29. #29
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: using a macro to copy a worksheet but change formulas cell references

    Excellent!

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. 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. Replies: 1
    Last Post: 03-13-2014, 03:09 PM
  2. Replies: 1
    Last Post: 02-09-2014, 05:49 PM
  3. [SOLVED] Run Time error when macro references copy range on a separate worksheet
    By CDEG in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-26-2013, 02:32 PM
  4. [SOLVED] Copy and paste formulas without changing cell references
    By davidx in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 08-20-2013, 03:34 PM
  5. [SOLVED] Change cell references in formulas
    By ozhunter in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-21-2013, 06:15 PM
  6. Macro to copy down pattern where row and column references change
    By alpha608 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-28-2013, 06:30 PM
  7. Replies: 4
    Last Post: 05-05-2011, 09:39 PM
  8. How do I copy formulas with cell references
    By msproles in forum Excel General
    Replies: 4
    Last Post: 01-13-2009, 11:57 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