To be clear, this counts number of lines, not number of line breaks. One line has zero line breaks. Two lines has one line break, etc.
This formula starts with the full length of each cell's contents (including line breaks) and then subtracts the length of each cell without those line breaks. That gives the total number of line breaks present, to which we add 1 to get the total number of lines.
Based on http://productforums.google.com/forum/#!category-topic/docs/formatting/-uEh3jguVu0 you can " copy the info single cell by single cell and paste the information in edit mode of the receiving cell; i,e. double-click the cell first before you paste the single cell contents". Though this is hardly 'easy' so there may be a better answer out there...
function result(range) {
var splitCol = 1; // split on column B
var output2 = [];
for(var i=0, iLen=range.length; i<iLen; i++) {
var s = range[i][splitCol].split("\n");
for(var j=0, jLen=s.length; j<jLen; j++) {
var output1 = [];
for(var k=0, kLen=range[0].length; k<kLen; k++) {
if(k == splitCol) {
output1.push(s[j]);
} else {
output1.push(range[i][k]);
}
}
output2.push(output1);
}
}
return output2;
}
Explanation
The script evaluates each row, and particularly the second column of each row (in JavaScript arrays are zero based, so column 2 corresponds to index 1 of the array). It splits the contents of that cell, into multiple values and uses the "\n" as delimiter (line feed). After that it adds the existing info to an array and only add the individual results, when it hits index 1 (k == 1). The newly prepared row is then added to another array, that's being returned to show the result.
Best Answer
Given your example setup:
=ArrayFormula(IF(A:A="",,LEN(A:A)-LEN(SUBSTITUTE(A:A,CHAR(10),""))+1))
To be clear, this counts number of lines, not number of line breaks. One line has zero line breaks. Two lines has one line break, etc.
This formula starts with the full length of each cell's contents (including line breaks) and then subtracts the length of each cell without those line breaks. That gives the total number of line breaks present, to which we add 1 to get the total number of lines.