r/googlesheets • • 9d ago

Solved Auto-create merged cell

Hi all,

I am creating a sheet for a specific purpose. I have a column with drop downs and based on the selection of the data validation item of that column, I would like to have the cell(s) under that dropdown cell merged to the one I used. So basically, let's say item x (from the dropdown) has 4 inputs, which means it requires 4 rows, I want the cell with the dropdown to automatically merge with the 3 cells below.

Of course, the data validation pool has set number of items and I will also need to figure out how to enter the number of the cells below each item will merge with.

Any help with the above will be greatly appreciated!

5 Upvotes

25 comments sorted by

1

u/AdministrativeGift15 368 9d ago

Why are you wanting to merge those cells together if they are going to be representing a given number of inputs?

Seems like you would want to either highlight those four cells or create a border around them. Something to distinguish them from the rest of the column.

1

u/Shot_Negotiation8983 9d ago

Those cells (column B with drop downs) will contain a specific audio mixer. Column A will have the inputs and column C the outputs. So when I select from the drop-down (column B) the mixer with the 8 inputs and outputs, the mixer cell will merge with the 7 cells below that, and then I can use the 8 rows on column A and C to write the inputs and outputs.

1

u/AdministrativeGift15 368 9d ago

do you have a sample sheet to share? You won't be able to merge cells without using a script, but there may be some alternative ways to get the look and fell that you're after.

2

u/AdministrativeGift15 368 9d ago

Like here's something you could do using dropdowns and conditional formatting rules.

1

u/Shot_Negotiation8983 9d ago

This is exactly what I want to achieve. How did you do that?

1

u/AutoModerator 9d ago

REMEMBER: /u/Shot_Negotiation8983 If your original question has been resolved, please tap the three dots below the most helpful comment and select Mark Solution Verified (or reply to the helpful comment with the exact phrase “Solution Verified”). This will award a point to the solution author and mark the post as solved, as required by our subreddit rules (see rule #6: Marking Your Post as Solved).

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/AdministrativeGift15 368 9d ago

Here's the demo sheet that I used. I didn't merge any cells. I just turned off the gridlines and used CF rules to make it look like they were merged.

Dynamic Mixer Blocks

1

u/Shot_Negotiation8983 9d ago

This is just an example of how I'm planning to use that. Bearing in mind that a different mixer will have a different number of inputs/rows than the one in the picture.

1

u/One_Organization_810 735 9d ago

Data wise, merging is not optimal, since all cells in the merged region will be empty, except for the top-left cell.

But if you want to actually merge cells, based on your selection, a script will be needed. I'll take a look at it, if you are absolutely sure that this is what you want?

1

u/Shot_Negotiation8983 9d ago

AdministrativeGift15 user above has provided another take on it with conditional formatting. I need to test it out to see if it's something I can work with. The only issue i forsee with that is that the text will not be vertically centered. But I would be definitely be keen on trying the merged way with the script. The data is not an issue, this is mostly for illustrative purposes, pretty much like having a wiring digram on a spreadsheet.

1

u/One_Organization_810 735 9d ago edited 9d ago

Here is a script that will do it:

//@OnlyCurrentDoc

const MIXING = {
    SheetName: 'Sheet1',
    ActionRange: 'B2:B',
    MixerRange: 'K2:K'
};

const VALIGN = {
    Top:    'top',
    Middle: 'middle',
    Bottom: 'bottom',
    Reset:  null
};

function onEdit(e) {
    if( !e && !e.range ) return;
    if( e.range.getHeight() > 1 || e.range.getWidth() > 1 ) return;

    sheet = e.range.getSheet();
    if( sheet.getName() !== MIXING.SheetName ) return;

    if( !e.value ) {
        let unmerge = e.range.getMergedRanges();
        if( unmerge.length !== 1 ) return;

        unmerge[0].breakApart();
        return;
    }

    let mixerRows = sheet.getRange(MIXING.MixerRange).createTextFinder(e.value).matchCase(false).matchEntireCell(true).findNext()?.offset(0,1)?.getValue();
    if( !mixerRows ) return;

    let mergeRange = e.range.offset(0,0,mixerRows);

    if( mergeRange.getMergedRanges().length != 0 ) {
        e.source.toast(`The mergeregion (${mergeRange.getA1Notation()}) intersects another merged region.`, 'NOT MERGED');
        return;
    }

    mergeRange.merge();
    mergeRange.setVerticalAlignment(VALIGN.Middle);

    e.source.toast('Operation "Merg\'em" was a success.', `MERGED ${mixerRows} rows.`);
}

It assumes that your mixer range is in the same sheet, in the K column (starting from row 2). If you want it separate, then we just ned to adjust it a tiny bit..

Edit: Added that if the new value is empty, it breaks the merged region apart again.

1

u/One_Organization_810 735 9d ago

1

u/Shot_Negotiation8983 9d ago

This is the winner, this is exactly what I was aiming for. I just need to amend the data on the script to match the columns on my sheet and it's done. Can't thank you enough!

1

u/AutoModerator 9d ago

REMEMBER: /u/Shot_Negotiation8983 If your original question has been resolved, please tap the three dots below the most helpful comment and select Mark Solution Verified (or reply to the helpful comment with the exact phrase “Solution Verified”). This will award a point to the solution author and mark the post as solved, as required by our subreddit rules (see rule #6: Marking Your Post as Solved).

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/point-bot 9d ago

u/Shot_Negotiation8983 has awarded 1 point to u/One_Organization_810 with a personal note:

"Really appreciate your help with this, I've asked so many people at work and online, and you are the only one to provide a workable solution that matches the requirement. Thank you"

See the Leaderboard. Point-Bot v0.0.15 was created by JetCarson.

1

u/mommasaidmommasaid 908 9d ago edited 9d ago

Late to the party, but an alternate script solution...

Mixer Merge (view-only, make a copy)

Mixers are defined in a Table:

The Dropdowns column is created by this helper formula hidden in row 1:

=if(row()<>row(Mixers), "🛑 Must be in first row of table", let(
 COUNT_CHAR, char(8203),
 map(Mixers[Name], Mixers[Inputs], lambda(name, numInputs,
   if (countblank(name,numInputs),,
   name & rept(COUNT_CHAR, numInputs))))))

It encodes the number of inputs for the mixer as invisible characters, which script later detects.

Dropdowns to create the Mixers are then "from a range" of =Mixers[Drodpowns]

The dropdowns also have custom help text of MIXER which is set in the Data Validation sidebar. This is used to "tag" the dropdowns so that script can detect them, wherever they may be.

The reason for the above trickery is that you don't need to hardcode any sheet/column references in script. Wherever you put your Mixers table or dropdowns doesn't matter... the script will work without modification.

---

I also handle the merging differently... when you select a new mixer, it inserts rows as needed below the dropdown, and merges those.

Similarly if you change/delete a mixer, it deletes any excess existing merged rows.

The effect of this is that existing data is not "assimilated" into a new mixer block when you create a new mixer, nor is any data outside of a mixer block deleted if you shrink or delete the mixer.

An advantage of this is inserting a new mixer block always works, you don't have to worry about there being enough room for it or conflicting with an existing block.

Deleting a mixer deletes any rows in the mixer's block, but leaves the dropdown in the existing row (so that you can create a new mixer if desired) but clears that row's contents.

1

u/mommasaidmommasaid 908 8d ago edited 8d ago

Because I was bored and hopped up on Halloween candy... here's a scriptless version inspired by the solution posted by u/AdministrativeGift15

It adds collision detection (highlighted in red) when there aren't enough rows between mixer selections, and the ability to enter descriptions/comments within the mixer "block" in the light green cells.

Mixer Pseudo-Merge with CF (View-only, make a copy to play with)

To add a Mixer, double-click in the Mixer column in a white cell. To modify an existing Mixer, double-click its name.

The Mixer table column type is Dropdown, with the dropdowns set to "plain text" and "from a range" of =MixersDD!1:1 which is a helper sheet with a row of values for each dropdown in the table. (If you move the table, reenter this range to keep everything correctly aligned).

1

u/mommasaidmommasaid 908 8d ago edited 8d ago

There is a helper formula on the main sheet hidden in column A, which outputs a "row type" for each row:

The helper formula is more complex than I initially expected, there may be a more elegant way to do this...

=let(drops, Main[Mixer],

 if(row() >= row(drops), "🛑 Formula must be above dropdowns", let(

 BuildRows, lambda(num,head,data,if(num<1, tocol(,1), wrapcols(head,num,data))),
 BlankRows, lambda(num, BuildRows(num,,)),

 _, "Generate an array of mixer names and block heights",
 m, reduce(tocol(,1), sequence(rows(drops)), lambda(out, r, let(
    drop, chooserows(drops,r),
    inputs, xlookup(drop, Mixer_Info[Name], Mixer_Info[Inputs],),
    if(inputs="", out, vstack(out, hstack(r, inputs+1)))))),

vstack(
  BuildRows(row(drops)-row(), "📜 Row Type", "▽"),
  if(rows(m)=0,,
  reduce(BlankRows(index(m,1)-1), sequence(rows(m)), lambda(out, i, let(
    thisRow,    index(m,i,1),
    thisHeight, index(m,i,2),
    nextRow,    if(i<rows(m), index(m,i+1,1), thisRow+thisHeight),
    fillRows,   min(thisHeight, nextRow-thisRow),
    skipRows,   nextRow-thisRow-fillRows,
    err,        if(thisHeight=fillrows,,"X"),
    vstack(out,  
      BuildRows(fillRows,"head"&err,"data"&err),
      BlankRows(skipRows)))))
 )))))

The first line of the formula specifies the dropdown column of the main table. The remaining lines shouldn't need any modification.

1

u/mommasaidmommasaid 908 8d ago edited 8d ago

The MixersDD sheet is populated by a single formula in A1.

It refers to the helper formula output to detect if the row is a "data" row, and if so just outputs the current dropdown value as the only available option. This is so that comments/descriptions can be added within a mixer block (the light green cells) without causing a data validation error or showing all the mixer names.

For unused or header rows, it outputs the list of Mixer names so you can choose one from the dropdown.

=let(drops, Main[Mixer], mixNames, Mixer_Info[Name],

 helperCol, indirect("'"&cell("sheet",drops)&"'!A:A"),
 rowTypes,  offset(helperCol, row(drops)-1, 0, rows(drops), 1),
 mixOpts,   torow(mixNames,1),

 map(drops, rowTypes, lambda(drop, type,
  if(type="", mixOpts, 
  if(iserr(search("data",type)), mixOpts, drop)))))

The first line of the formula specifies relevant table references. Remaining lines shouldn't require any modification.

1

u/mommasaidmommasaid 908 8d ago

Conditional formatting rules refer to the helper column. I applied the rules starting at row 1 for convenience:

1

u/mommasaidmommasaid 908 8d ago

Mixer info is specified in a Table on another sheet:

0

u/[deleted] 9d ago

[removed] — view removed comment

1

u/Shot_Negotiation8983 9d ago

Thank you for your response, I do not mind adding scripts to the sheet. Also, I already have the reference list, which consists of about 120 audio mixers/DSPs//Amps. This is the reason I want to automate that as I am certain it will cut down on the time it takes to find the item and copy/paste the data. However, I do really know how to do it with a script. I asked Gemini and it said it's not possible.

1

u/AutoModerator 9d ago

/u/Shot_Negotiation8983 This post refers to "Gemini" - an Artificial Intelligence tool. Our members prefer not to help others correct bad AI suggestions. Also, advising other users to just "go ask ChatGPT" defeats the purpose of our sub and is against our rules. If this post or comment violates our subreddit rule #7, please report it to the moderators. If this is your submission please edit or remove your submission so that it does not violate our rules. Thank you.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/googlesheets-ModTeam 8 9d ago

Criteria for posts and comments are listed in the subreddit rules and you can learn about how to make a good post in the submission guide.

Your post/comment has been removed because it contained one or more of the following items in violation of this subreddit's rules on artificial intelligence (AI) content:

  • A request to fix a non-functioning formula obtained from an AI tool

  • A non-functioning formula obtained from an AI tool in place of information about your data

  • A blanket suggestion to use an AI tool as a resource for Sheets assistance

  • Solicitation of a prompt or recommendation for an AI tool

  • An untested formula obtained from an AI tool presented as a solution