r/googlesheets • • 3d ago

Waiting on OP Split Row into Multiple Rows

Post image

Was wondering if theres a way to a row with data into multiple rows. Some of my dads data got merge into 1 row and we want to spli the row without have to re type the data. Also my bad is stupid when comes to computers hes almost 80. So was just wondering if theres is a way to do that.

So for example Row 5 has 3 names dates payments, but we want each of those in their own row, how do we do that with out deleting everything in row 5 and just put everything in its own row.

No thats not the real data thats just stupid quick example i made. my dads daya is a bit more. then that,

3 Upvotes

14 comments sorted by

1

u/HolyBonobos 3124 3d ago

Probably not in a way you'd consider satisfactory, at least not natively. Working with the data shown in the screenshot, you could split out the entries into a new dynamic range with a formula like =QUERY(WRAPROWS(TOROW(BYROW(A2:D7,LAMBDA(i,TOROW(INDEX(SPLIT(TRANSPOSE(i),CHAR(10))),,1)))),4),"WHERE Col1 IS NOT NULL LABEL Col1 'Name', Col2 'Date', Col3 'Owed', Col4 'Paid' FORMAT Col2 'mm/dd/yy', Col3 '$0', Col4 '$0'"). This would read the "messed-up" data and use it to automatically create a "clean" dataset in a different part of the file (assuming line breaks are consistently used to separate entries within the same cell), and would update as changes are made to the editable range.

Do note, though, that the editable range would remain the one with the "messed-up" data. Attempts to directly edit the entries in the "clean" data created by the formula would prevent it from expanding and break it, resulting in a #REF! error. You could change the formula output into a new editable range by copy-pasting values (Ctrl+C then Ctrl+Shift+V) and deleting the original data, but this would only really serve as a temporary fix and would not prevent future mistakes. You could do some data validation to put up some roadblocks for predictable errors, but when the underlying problem is the user behaving in unexpected and improper ways, there's only so much you can do about it.

1

u/FireDracon 3d ago

So no easy way to split row 5 into 3 different tows besides just re-entering the info. Into 2 other rows .Right.

3

u/HolyBonobos 3124 3d ago edited 3d ago

If you’re doing it manually then yes. There’s the formula-based approach that I suggested in the previous comment, but it comes with several asterisks and expects a certain degree of regularity that user error isn’t likely to consistently provide. While it works with the sample data in your post, it may not be the best solution for your particular scenario.

1

u/AutoModerator 3d ago

/u/FireDracon Posting your data can make it easier for others to help you, but it looks like your submission doesn't include any. If this is the case and data would help, you can read how to include it in the submission guide. You can also use this tool created by a Reddit community member to create a blank Google Sheets document that isn't connected to your account. 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/AdministrativeGift15 370 2d ago

Try this:

=INDEX(REDUCE(A1:D1,SEQUENCE(COUNTA(A:A)-1,1,2),LAMBDA(t,c,VSTACK(t,TRANSPOSE(SPLIT(TRANSPOSE(INDEX(A:D,c,)),CHAR(10)))))))

You'll just need to apply the correct date format to column B afterwards.

1

u/One_Organization_810 736 2d ago edited 1d ago

Try this one in an empty area. Expand as needed.

Assuming this is just a one time fixing operation, just copy the results back over the source and then delete the formula.

=reduce(tocol(,1), A2:D, lambda(stack, data,
ifna(vstack(stack, index(split(data, char(10)))))
))

1

u/One_Organization_810 736 1d ago

Lol - sorry u/FireDracon, i must have been half asleep when i proposed this one :) REDUCE doesn't work on whole rows, so we need to adjust a little bit (amongst other things)... here is a revised formula (and tested) :

=let( data, filter(A2:D, A2:A<>""),
      reduce(tocol(,1), sequence(rows(data)), lambda(stack, r,
        ifna(vstack( stack,
                     map(chooserows(data,r), lambda(x,
                       tocol(split(x, char(10)))
                     ))
        ))
      ))
)

Again, sorry for the confusion.

1

u/djpresstone 2d ago

In A8, a9, a10: =index(split(a5, char(10)), 1, row()-7)

Then just copy to b, c, & d and bob’s your uncle

0

u/carbonizedtitanium 28 2d ago edited 2d ago

Assuming that all the "defective" rows are the same (i.e. it's just the data separated by a newline char and all columns in the same row have the same amount of newlines), you can use GAS script to automatically split all rows that contain newline chars into individual rows:

go to Extensions >> Apps Script >> replace the default text with the following script, replace the sheet tab name with the name of your own tab name, and save. then click Run and follow the instructions to allow permissions for the script to run.

function splitNewlinesIntoRows() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getSheetByName('Sheet15'); // Replace Sheet15 with your own Sheets tab Name
  
  const startRow = 1; // header row
  const lastRow = sheet.getLastRow();
  const lastCol = sheet.getLastColumn();
  
  if (lastRow < startRow) return;

  const range = sheet.getRange(startRow, 1, lastRow - startRow + 1, lastCol);
  const values = range.getValues();
  const expandedRows = [];

  values.forEach(row => {
    // Split every cell in the row by newline
    const splitCells = row.map(cell => String(cell).split(/\r?\n/));
    
    // Find the maximum number of lines in this row
    const maxLines = Math.max(...splitCells.map(lines => lines.length));
    
    // Build individual rows for each line index
    for (let i = 0; i < maxLines; i++) {
      const newRow = splitCells.map(lines => lines[i] !== undefined ? lines[i] : "");
      expandedRows.push(newRow);
    }
  });

  // Clear original range and write the expanded rows back
  range.clearContent();
  sheet.getRange(startRow, 1, expandedRows.length, lastCol).setValues(expandedRows);
}

P.S. To avoid the same problem from happening, i suggest you create a Google Forms file and link it to the spreadsheet. Use the Google Forms to log transactions into the spreadsheet, instead of directly entering the data into the sheet. using Google Forms to enter the data prevents the problem that you currently have.

ideally, your Google Forms should ask:

  • Who or What the transaction is for
  • What type of transaction it is (example choices: Debt or Payment)
  • The amount of the transaction

with the data from the Form, you can then create a Dashboard tab of what is (or was) owed and how much, using formulas.

-3

u/TRI140dot6 3d ago

PAYED should be PAID

0

u/[deleted] 21h ago

[removed] — view removed comment

1

u/googlesheets-ModTeam 8 6h ago

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

Your comment has been removed because it broke rule 7, which governs AI and AI-related content. If you have questions about why your comment was removed or believe you have edited it so that it no longer violates the rules, you can message the moderators.

Specific violations:

  • AI-generated content