Google-sheets – How to prevent cut-and-paste data from changing collapsed grouped cells

copy/pastegoogle sheets

I'm completely lost and don't know how to paste any data without affecting those collapsed rows.

For example, I have such a list:

\Sample table in Google Sheets

And I want to paste numbers from 1 to 4 for every capital letter into the second column. I'm collapsing all grouped letters:

Collapsing grouped letters in sample table

But when I select the second column and paste the copied array of numbers, it overwrites all cells, including the collapsed ones. Like this:

Problem with cmd-c cmd-v for collapsed grouped rows 1

Problem with cmd-c cmd-v for collapsed grouped rows 2

Can anybody please explain how can I paste data without overwriting the cells from hidden rows?

Best Answer

Not really possible to prevent this from happening in Google Sheets, but there are always ways with formulas...

=ARRAYFORMULA(REGEXREPLACE(TO_TEXT(COUNTIFS(IFERROR(REGEXREPLACE(
 REGEXEXTRACT(A1:A, "^[A-Z]"), "[A-Z]", "A")), IFERROR(REGEXREPLACE(
 REGEXEXTRACT(A1:A, "^[A-Z]"), "[A-Z]", "A")), ROW(A1:A), "<="&ROW(A1:A))*
 COUNTIFS(A1:A, A1:A, ROW(A1:A), "<="&ROW(A1:A))), "^0", ""))

0