Hey everyone! I need help with something in Google Sheets. I want to combine cells that are next to each other vertically when they have the same content.
|"A"| |"A"|
|"A"| ---> | |
|"A"| | | (combined)
I’m building a daily activity tracker and it would be great if similar tasks get combined into one block. For example, if I have “work” in multiple rows, they should merge into one big cell. Same thing for “exercise” or any other activity.
I only need this to work up and down, not left to right. The data I’m working with is in cells C30 through J150.
I tried looking at some code examples but couldn’t get them working properly. Not sure if it’s because I’m not good with coding.
Also, is there a way to keep track of how many cells got merged together? Like if 5 cells become 1, I want to store that number 5 somewhere. Maybe in a cell comment? This would help me calculate how much time I spent on each activity.
sheets can’t auto-merge cells without heavy scripting. i just fake it with conditional formatting - match the border colors to the background so identical cells look like they flow together. way simpler than actual merging and won’t mess up your data later.
I faced similar challenges when managing my project tracking in Google Sheets. Unfortunately, it doesn’t support automatic merging of cells based on content; the merging process must be done manually. Instead, I implemented a helper column with formulas to create a visual grouping. You can achieve an effect similar to merging by using conditional formatting—removing borders between identical values and applying the same background color. For keeping track of how many entries there are, I utilized COUNTIF formulas in adjacent columns to count occurrences of each activity. While this doesn’t provide the same functionality as actual merging, it preserves your data structure while offering a visual distinction and counting mechanism. Although using Google Apps Script is an option, it can become complex and may break with data alterations. The visual formatting method has reliably worked for me over time.
Google Sheets can’t automatically merge cells based on content, but I’ve found a workaround using Apps Script for my inventory sheets. You can create a script that runs periodically to find consecutive identical values and merge those cells programmatically. But heads up - merged cells mess with formulas and data manipulation later. I’ve had better luck creating a visual effect using borders and background colors while keeping the actual data untouched. For counting merged instances, try this formula: =IF(C30<>C29,COUNTIF(C30:INDEX(C:C,MATCH(FALSE,C30:C150=C30,0)-1),C30),"") - it counts occurrences only on the first instance of each group.