+ Reply to Thread
Results 1 to 5 of 5

Add or delete rows from a selection

  1. #1
    Registered User
    Join Date
    12-07-2022
    Location
    Hoorn
    MS-Off Ver
    2210 excel
    Posts
    22

    Add or delete rows from a selection

    Hi guys,

    I've been working on a dashboard recently.
    I need to visualize a set of pivot tables. The size of the pivot tables, however, vary in accordance with the underlying input.
    This means that the tables may expand or shrink from time to time as I update the raw data.

    Pivot tables can not overlap, nor do I want to use an excessive amount of space since that would impede the accessibility of the sheet.

    My opted/theoretical solution using macro's:

    Add an arbitrary amount of cells underneath a pivot table to create space for the table to expand;
    Refresh the pivot table (for this, a macro has already been created so no further need to develop that);
    Have the offset formula calculate the length of my refreshed pivot table;
    Delete the excessive cells to minimize the used space in the dashboard.

    I have, however, not been able to work this out by myself and would like some advice

    I added a sample sheet.
    Here, for example, I would want cells to be added in e41:q41 and have everything underneath shift it down, in accordance with the amount of new products i would add in the input (left 4 collumns).

    Many thanks in advance!
    Attached Files Attached Files
    Last edited by TDus; 12-09-2022 at 11:35 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    11-29-2022
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    430

    Re: Add or delete rows from a selection

    So the problem you mention is why I never make my pivot tables stack on top of each other, always side-by-side, unless the number of rows is static (like 1 hour intervals in a day). But, if you have to have them on top of each other, then hide the rows instead of inserting and deleting them. So, to start, put a stupid number of blank rows in between them, something that the top pivot will never fill, say maybe like 200 rows, so that the bottom Pivot begins on row 250. Then a piece of code like this should work:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-07-2022
    Location
    Hoorn
    MS-Off Ver
    2210 excel
    Posts
    22

    Re: Add or delete rows from a selection

    Hahaha apologies for the dutch in there

    I have thought about this too but since pivot tables from the left to the right may also vary in length, hiding rows was not an adequate solution.
    Regardless, I will try to work out your solution a bit further and see if i can make it work.

    Thanks for the input!

  4. #4
    Valued Forum Contributor
    Join Date
    11-29-2022
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    430

    Re: Add or delete rows from a selection

    You can also search for the last row in each pivot using that Eindtotaal. Then compare to see which row is further down and use that as lrow to build the string of what to hide.

  5. #5
    Registered User
    Join Date
    12-07-2022
    Location
    Hoorn
    MS-Off Ver
    2210 excel
    Posts
    22

    Re: Add or delete rows from a selection

    What I did right now is work with the offset formula as i mentioned earlier:

    =match("Grand total";Dashboard2!Q:Q;0)+1 --> name value "CI_Start"
    =match("End critical";Dashboard2!Q:Q;0)-1 --> name value "CI_End"

    =offset(Dashboard2!$P$1;CI_Start;0;CI_End-CI_Start;4) --> name range "Selection"

    Then, in VBA:

    Range("Selection").Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove <<x50>>

    Then, to prune back excessive rows, I created something similar to this but in reverse

+ 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. Delete rows in scattered selection
    By ESF in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-09-2012, 06:22 AM
  2. Delete rows in a selection?
    By scottkrise05 in forum Excel General
    Replies: 1
    Last Post: 07-08-2010, 08:49 PM
  3. Delete blank rows on manual selection
    By jdbegg in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-12-2006, 05:54 PM
  4. Delete blank rows in selection
    By Chris_t_2k5 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-13-2006, 05:20 PM
  5. RE: Delete blank rows in selection
    By Chris_t_2k5 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2006, 04:45 PM
  6. [SOLVED] RE: Delete blank rows in selection
    By Gary''s Student in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2006, 04:45 PM
  7. RE: Delete blank rows in selection
    By Jim Thomlinson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2006, 04:45 PM
  8. Need to delete rows relative to selection
    By ratchick in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-22-2005, 12:55 PM

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