Forum Discussion

Sid_Broach's avatar
Sid_Broach
Copper Contributor
May 04, 2024

How can I resize a level 2 grouping in a row-based outline structure.

PC/Windows 10
Microsoft 365
Version 2403 Build 16.0.17425.20176) 32-bit

 

Summary: I need to reset a level 2 grouping in a row-based outline structure to match a new size (i.e. adjust the number of lines within a sub-group directly).

 

Issue: I know how to set up outline levels, but the only way I know of to readjust the number of rows in a level 2 grouping is to delete the entire outline structure and recreate my outline groupings from scratch.

 

Hoped for Result: I would like to find a way to simply select and adjust the number of rows in any particular existing level 2 sub-grouping directly (rather than recreate the entire outline structure).

===========================================

Description: I have a simple spreadsheet in Excel where I keep weekly paycheck figures for my wife. I use a 2-level outline to divide the paycheck rows into Year (Level 1) and Month (Level 2) to make things easy to work with.

 

Each year, I copy the prior year's outline into a new tab, empty the existing data, and use the now empty sheet as my template for the new year's work. Of course, the number of paycheck weeks within each month changes with the year.  But I find that as I create the right number of weeks within each month (adding and deleting lines to match the paydates), the Month (level 2) grouping 'edges' get slightly off, that is, the beginning and end of that Level 2 group become off by a row of two as I add/delete lines within that particular group. That many times propagates down the level 2 outline, altering the boundaries for other months in ways both weird and wonderful.  I would like to reset any particular Month (level 2) grouping directly to match the new actual month groupings without affecting other level 2 groupings.  Can you help me?

  • NikolinoDE's avatar
    NikolinoDE
    Gold Contributor

    Sid_Broach 

    It seems like you are looking for a way to adjust the size of a Level 2 grouping in a row-based outline structure without having to recreate the entire outline structure.

    While Excel does not offer a direct way to resize individual groupings within an outline, there are a few workarounds you can try:

    1. Manually Adjust Row Heights:
      • You can manually adjust the row heights to match the desired grouping. Select the rows you want to include in the Level 2 grouping, right-click, choose "Row Height", and enter the desired height. This method may be tedious if you have many rows to adjust.
    2. Use a Macro:
      • You can create a macro to automate the process of resizing the row heights for specific Level 2 groupings. The macro would select the rows for the desired grouping and adjust their height accordingly. Here's a basic example of what the macro might look like:

    Vba code is untested, please backup your file frst.

    Sub ResizeLevel2Grouping()
        ' Select the range of cells for the Level 2 grouping
        Dim rng As Range
        Set rng = Range("A1:A10") ' Adjust the range as needed
        
        ' Set the desired row height
        Dim rowHeight As Double
        rowHeight = 25 ' Adjust the row height as needed
        
        ' Resize the row heights
        rng.RowHeight = rowHeight
    End Sub

    You can customize this macro to select the specific range of cells for your Level 2 grouping and set the desired row height.

    3. Use Formulas for Dynamic Row Heights:

      • You can use formulas to dynamically adjust the row heights based on the number of rows in each grouping. For example, you could use a formula in the row height property of each row to calculate the height based on the number of rows in the grouping.

    These workarounds may require some manual effort or scripting, but they should allow you to adjust the size of individual Level 2 groupings without affecting the rest of the outline structure. If you were comfortable with VBA scripting, the macro approach would likely be the most efficient solution. The text, steps and code were created with the help of AI.

     

    My answers are voluntary and without guarantee!

     

    Hope this will help you.

    Was the answer useful? Mark as best response and Like it!

    This will help all forum participants.

    • Sid_Broach's avatar
      Sid_Broach
      Copper Contributor
      Thanks - I'll take a closer look at your suggestions. On first glance, It seems that you are addressing row heights, instead of the NUMBER of rows in each Level 2 (monthly) grouping. Maybe I didn't describe my issue clearly, but row height is not my issue, just changing the number of rows included in each Level 2 (Monthly) grouping to reflect each year's varying number of paydays in any particular month.
      • NikolinoDE's avatar
        NikolinoDE
        Gold Contributor

        Sid_Broach 

        Thank you for clarifying your needs. It looks like you need a way to adjust the number of rows in each Level 2 grouping in an Excel outline to match the varying number of paydays in each month without having to recreate the entire outline structure.

        Adjusting Level 2 Groupings in Excel

        In Excel, there isn't a direct feature to resize specific outline groups dynamically. However, you can achieve your goal by using a combination of VBA to adjust the groups programmatically. This method allows you to change the grouping ranges without affecting other parts of your outline structure.

        Here's a step-by-step approach to achieve this:

        Using VBA to Adjust Groupings

        1. Identify the ranges to be grouped/un-grouped.
        2. Use VBA to dynamically adjust these ranges based on your specific requirements.

        Below is a VBA script that you can use to adjust the groupings for a specified range dynamically. This example will show how to ungroup and regroup rows based on a specified number of rows for each group:

        Step-by-Step VBA Solution

        1. Open the VBA Editor:

        • Press Alt + F11 to open the VBA editor in Excel.

        2. Insert a New Module:

        • In the VBA editor, insert a new module by right-clicking on any existing module and selecting Insert > Module.

        3. Copy the VBA Code:

        • Paste the following VBA code into the new module:

        Vba Code is untested, Backup your file first.

         

        4. Run the Macro:

        • Close the VBA editor.
        • Press Alt + F8 to open the Macro dialog box.
        • Select AdjustLevel2Grouping and click Run.

        Explanation of the Code:

        1. Setting the Worksheet and Ranges:

        • The ws variable sets the target worksheet.
        • yearStartRow and yearEndRow define the range of rows for the year.

        2. Looping Through Months:

        • The macro loops through each month and adjusts the number of rows in the Level 2 grouping based on the predefined groupSize for each month.
        • It then ungroups any existing groups in the specified range and applies new grouping.

        3. Dynamic Group Sizes:

        • You can modify the groupSize values to reflect the number of paydays for each month.

        Customizing for Your Needs:

        • Adjust the yearStartRow, yearEndRow, and groupSize values to fit your specific data structure and requirements.
        • Change the sheet name Sheet1 to the actual name of your worksheet containing the data.

        This VBA script provides a flexible way to adjust Level 2 groupings dynamically based on the number of rows you specify for each month, thus avoiding the need to recreate the entire outline structure from scratch each time. The text, steps and code were created with the help of AI.

         

        My answers are voluntary and without guarantee!

         

        Hope this will help you.

        Was the answer useful? Mark as best response and Like it!

        This will help all forum participants.

Resources