0

I'm using BYROW to pull a string of dates from one sheet and make a list of those dates in a single cell on another sheet. Now I'm trying to use LEN and SUBSTITUTE to count the number of dates in that cell:

=LEN(M13)-LEN(SUBSTITUTE(M13,",",""))+1

I have to add the +1 at the end of the formula to count the last date, but some cells have no dates, and I need those to pull a 0 if they stay blank. Does this make sense? So if I add a comma after the last date, it throws off my BYROW function that gets me the dates in the first place.

https://docs.google.com/spreadsheets/d/1MRkacDUNoa0QXMYG5njBp7E7NepRARKXb4IEHjWnxsw/edit?usp=sharing

1 Answer 1

0

You can simply nest the LEN inside an IF to first check the cell if it's empty, in which case it will output empty (or 0 if you want.)

Something like:

=IF(M2<>"",LEN(M2)-LEN(SUBSTITUTE(M2,",",""))+1,"")
  • IF M2 is not empty, output the result of the LEN
  • IF M2 is empty, output empty (change the last "" to 0 if you want a 0 instead)
2
  • That is beautiful. Thank you. Why is this all so hard to learn? I wish my brain was better-adapted to understanding all of this. Thank you so much! Commented Apr 19, 2023 at 19:38
  • You learn by utilizing it... Nesting an IF in this way comes in handy a lot of times, so if you understand what it is that we did here you can adapt it to whenever you need it Commented Apr 19, 2023 at 19:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .