+ Reply to Thread
Results 1 to 15 of 15

How to have macro copy & paste cells below collapsed group?

  1. #1
    Forum Contributor
    Join Date
    02-18-2020
    Location
    Ottawa, ON
    MS-Off Ver
    Professional Plus 2010
    Posts
    122

    Exclamation How to have macro copy & paste cells below collapsed group?

    Hi there,

    I have a macro that copy cells from "data" and pastes them under my current work in "Projects", but this macro only works when the grouped cells in "Projects" are expanded. It the grouped cells are collapsed, then the macro will replace some of the collapsed information. How do I prevent this from happening?

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Keegan1116; 03-06-2020 at 03:07 PM.

  2. #2
    Registered User
    Join Date
    02-19-2020
    Location
    Russian Federation
    MS-Off Ver
    2010
    Posts
    9

    Re: How to have macro copy & paste cells below collapsed group?

    You can try this calculation of true last row:

    Please Login or Register  to view this content.
    instead of this line:

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    02-18-2020
    Location
    Ottawa, ON
    MS-Off Ver
    Professional Plus 2010
    Posts
    122

    Re: How to have macro copy & paste cells below collapsed group?

    Okay so it only works once, because it keeps replacing the same cells every time I run it. I leave 1 blank row at the end of every checklist to separate the projects, and this macro is now adding another blank line before pasting the cells, so the macro sees that space and thinks that's where it all ends.

  4. #4
    Registered User
    Join Date
    02-19-2020
    Location
    Russian Federation
    MS-Off Ver
    2010
    Posts
    9

    Re: How to have macro copy & paste cells below collapsed group?

    May be it would be better to set the Header for every project... then macro would see this header instead of space. Is it possible?
    Like here:

    Attachment 666208

  5. #5
    Registered User
    Join Date
    02-19-2020
    Location
    Russian Federation
    MS-Off Ver
    2010
    Posts
    9

    Re: How to have macro copy & paste cells below collapsed group?

    Also you can calculate true last row other way (but I don't like this way):

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    02-18-2020
    Location
    Ottawa, ON
    MS-Off Ver
    Professional Plus 2010
    Posts
    122

    Re: How to have macro copy & paste cells below collapsed group?

    I have attached a copy of the file (minus details) so you can see what is happening. The macro is linked to a button on the toolbar (far right tab).

    I cant' see the example you posted about, I don't have admin privileges apparently.. lol But the reason I wanted to do it this way, was because its a pain to have to copy and paste in templates every time, besides that, I would like other people to be able to use this when it's finished, and we both know how terrible some people are with computers. I want it to be completely fool-proof - Push a button, template pops up, enter the information for this project and off you go.

    As for your second reply; Will this fix my current issue? Why don't you like that method?

  7. #7
    Forum Contributor
    Join Date
    02-18-2020
    Location
    Ottawa, ON
    MS-Off Ver
    Professional Plus 2010
    Posts
    122

    Re: How to have macro copy & paste cells below collapsed group?

    Also I forgot to ask, but which part of the macro code would I replace this new code with for it to function properly?

  8. #8
    Forum Contributor
    Join Date
    02-18-2020
    Location
    Ottawa, ON
    MS-Off Ver
    Professional Plus 2010
    Posts
    122

    Re: How to have macro copy & paste cells below collapsed group?

    Hey there, sorry to keep bothering you , but have you had a chance to look at this again? I've been really struggling to find a solution to this

  9. #9
    Registered User
    Join Date
    02-19-2020
    Location
    Russian Federation
    MS-Off Ver
    2010
    Posts
    9

    Re: How to have macro copy & paste cells below collapsed group?

    Sorry it took so long... I corrected my code and made it more universal. I tested it in your file and now it works. So just replace your code in Module1 on this:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    02-19-2020
    Location
    Russian Federation
    MS-Off Ver
    2010
    Posts
    9

    Re: How to have macro copy & paste cells below collapsed group?

    As for your second reply; Will this fix my current issue?
    About it... Yes, I thought it should fix your issue, but I didn't know that you have got merged cells in your data, so now I needed to change my code.

    Why don't you like that method?
    This method isn't universal and it isn't very "gracefully".

  11. #11
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,523

    Re: How to have macro copy & paste cells below collapsed group?

    Re: "I didn't know that you have got merged cells in your data"
    Merged cells should be replaced by "Center Across Selection"
    I've seen helpers say that they refuse to help where there are Merged Cells involved.

  12. #12
    Forum Contributor
    Join Date
    02-18-2020
    Location
    Ottawa, ON
    MS-Off Ver
    Professional Plus 2010
    Posts
    122

    Re: How to have macro copy & paste cells below collapsed group?

    Yes!! It works!!! So whats the defining difference here? I see a lot of new code, but what exactly is it doing? Thanks again!

  13. #13
    Forum Contributor
    Join Date
    02-18-2020
    Location
    Ottawa, ON
    MS-Off Ver
    Professional Plus 2010
    Posts
    122

    Re: How to have macro copy & paste cells below collapsed group?

    I really want to thank you for helping me with this. This was the final step in completing my spreadsheet that I have been working on for months. It will now be used for my entire team!

  14. #14
    Registered User
    Join Date
    02-19-2020
    Location
    Russian Federation
    MS-Off Ver
    2010
    Posts
    9

    Re: How to have macro copy & paste cells below collapsed group?

    My pleasure!
    I'm really glad I could help!

    So whats the defining difference here?
    I changed the method of calculation of last row in destination worksheet. I wrote function named CalcLastRowNumber that returns number of the last row. This function checks every row in destination worksheet: if this row "is empty" (all values of cells in columns №№ 1, 2, 3 and 4 = "") and next two rows "are empty" too then we can think that the previous row is last.
    Function RowIsEmpty checks if this row "is empty". Because there are merged cells in your data we should get value using MergeArea property. If we try to get data the usual way we can fail. That is because data contains only in first of the merged cells. Properties MergeArea.Row and MergeArea.Column returns the Row and Column of the cell which contains our data. So thats why we use MergeArea property.
    So I hope you will understand my explanation. >.<

  15. #15
    Forum Contributor
    Join Date
    02-18-2020
    Location
    Ottawa, ON
    MS-Off Ver
    Professional Plus 2010
    Posts
    122

    Re: How to have macro copy & paste cells below collapsed group?

    I understand well enough I'm really glad this project is now complete. Have a great day!

+ 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: 10-08-2016, 08:24 PM
  2. Macro to copy group of cells and paste multiple times for each row of data
    By muddakinjaz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-09-2016, 01:17 PM
  3. [SOLVED] Macro to copy,paste and group information based on value in a cell
    By gullit in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-14-2012, 05:32 PM
  4. [SOLVED] Hide Scrolling Table Scrollbar when Group Collapsed
    By HangMan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-18-2012, 09:44 AM
  5. Macro to copy and paste into cell group in NXT ROW
    By L-plate in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-17-2011, 07:45 AM
  6. [SOLVED] Calculate,Copy, Paste Cell Group Macro Adjustments
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-28-2006, 11:50 PM
  7. [SOLVED] Hide collapsed group headers on print
    By [email protected] in forum Excel General
    Replies: 0
    Last Post: 10-07-2005, 03:05 AM

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