How to find if cell adjacent to a blank cell is also blank?

How can I use a formula in a header row to look down a specific column to search for blanks in that column, and if a blank is found: search the adjacent column in that same row where the blank is to see if there’s another blank next to it?


[This question is related to my other question, but I felt it was different enough that it deserved its own post for clarity. You can view my other post/question by clicking here.]

Posted on Jun 15, 2023 1:52 PM

Reply
Question marked as Top-ranking reply

Posted on Jun 20, 2023 11:07 AM

Badunit wrote:

I'm not sure there is a function that can determine if two adjacent cells are totally blank (those where ISBLANK would return TRUE). A formula that checks for "" (null string) will work for cells that are blank or have the formula result of "".

IF(COUNTIFS(B,"",C,"")>0,"Adjacent Blanks","No Adjacent Blanks")


I'm going to be honest, I don't know why I didn't try this when you posted it... I believe this is exactly what I'm looking for. I think I just didn't understand how it worked. Does it essentially act like an AND function, counting only if ALL conditions are met?


Badunit wrote:

Also, as with the COUNTIFS formula I provided, TEXTJOIN with the FALSE parameter gives the same result for "" or blank cells. If you need them to be absolutely blank, you may need to use a column of formulas to check each row individually with AND(ISBLANK(A),ISBLANK(B)).

I notice that TEXTJOIN with the TRUE parameter will skip over blank cells but will include cells with "".


This is an interesting observation. I was playing around with this and one way I found to be able to detect this and prevent this confusion in results would be to use a combination of =COUNTA and =COUNTIFS with regex to 'check' the data.


As a test, I input "" in cell B10. If I use your initial suggestion with the formula: "COUNTIFS(Table 1::A,"",Table 1::B,"")" I only get a result of 3 double blanks instead of 4 (since cell B10 is technically not blank), as you pointed out would happen. However, if I use "COUNTA(Table 1::A:B)" (which is the formula under "COUNTA") and "COUNTIFS(Table 1::A:B,REGEX("\d{1,3}((\,\d{3})+)*\.\d{2}",case-sensitive))" (which is the formula under "REGEX MATCH"), I can have another formula that checks those two numbers to make sure they are the same number. If so, there should be no cells with ""(null strings/fake blanks). It is essentially making sure the total number of cells that are not blank = all the cells that are formatted as they're supposed to be for my needs (as defined by my regex). (For anyone else, I suppose the regex could be changed to fit your needs or a different function might be used to compare to COUNTA).


Please correct me if I'm wrong but from here, by using this in addition to "COUNTIFS(Table 1::A,"",Table 1::B,"")" this should work flawlessly to detect two adjacent blanks while also making sure that null strings ("") do not throw off the data, correct?

19 replies
Question marked as Top-ranking reply

Jun 20, 2023 11:07 AM in response to Badunit

Badunit wrote:

I'm not sure there is a function that can determine if two adjacent cells are totally blank (those where ISBLANK would return TRUE). A formula that checks for "" (null string) will work for cells that are blank or have the formula result of "".

IF(COUNTIFS(B,"",C,"")>0,"Adjacent Blanks","No Adjacent Blanks")


I'm going to be honest, I don't know why I didn't try this when you posted it... I believe this is exactly what I'm looking for. I think I just didn't understand how it worked. Does it essentially act like an AND function, counting only if ALL conditions are met?


Badunit wrote:

Also, as with the COUNTIFS formula I provided, TEXTJOIN with the FALSE parameter gives the same result for "" or blank cells. If you need them to be absolutely blank, you may need to use a column of formulas to check each row individually with AND(ISBLANK(A),ISBLANK(B)).

I notice that TEXTJOIN with the TRUE parameter will skip over blank cells but will include cells with "".


This is an interesting observation. I was playing around with this and one way I found to be able to detect this and prevent this confusion in results would be to use a combination of =COUNTA and =COUNTIFS with regex to 'check' the data.


As a test, I input "" in cell B10. If I use your initial suggestion with the formula: "COUNTIFS(Table 1::A,"",Table 1::B,"")" I only get a result of 3 double blanks instead of 4 (since cell B10 is technically not blank), as you pointed out would happen. However, if I use "COUNTA(Table 1::A:B)" (which is the formula under "COUNTA") and "COUNTIFS(Table 1::A:B,REGEX("\d{1,3}((\,\d{3})+)*\.\d{2}",case-sensitive))" (which is the formula under "REGEX MATCH"), I can have another formula that checks those two numbers to make sure they are the same number. If so, there should be no cells with ""(null strings/fake blanks). It is essentially making sure the total number of cells that are not blank = all the cells that are formatted as they're supposed to be for my needs (as defined by my regex). (For anyone else, I suppose the regex could be changed to fit your needs or a different function might be used to compare to COUNTA).


Please correct me if I'm wrong but from here, by using this in addition to "COUNTIFS(Table 1::A,"",Table 1::B,"")" this should work flawlessly to detect two adjacent blanks while also making sure that null strings ("") do not throw off the data, correct?

Jun 20, 2023 11:13 AM in response to Badunit

Badunit wrote:

See my post on bugs.


Are you referring to what you said earlier (quoted below)?

Also, as with the COUNTIFS formula I provided, TEXTJOIN with the FALSE parameter gives the same result for "" or blank cells. If you need them to be absolutely blank, you may need to use a column of formulas to check each row individually with AND(ISBLANK(A),ISBLANK(B)).

I notice that TEXTJOIN with the TRUE parameter will skip over blank cells but will include cells with "". Maybe that can be used...
...but I think that is a bug in the TEXTJOIN function so I wouldn't try to exploit it.

If so, I would agree with stfflspl here and I don't see how that's a bug.

If not, could you please link your post?

Jun 20, 2023 11:29 AM in response to SGIII

SGIII wrote:

I'm thinking there may be an easier solution if you add a third column and fill it with a character you wouldn't be using otherwise (perhaps a ^) and then apply TEXTJOIN to A:C

Aha! This works well! Using this, I get the following result:

2.99~~^~4,000.00~~^~2.99~~^~~51.99~^~0.01~~^~~60.00~^~43.39~~^~~25.00~^~257.69~~^~~~^~~~^~~50.00~^~1.00~40.00~^~~~^~942.96~~^


From here, I'd imagine a simple COUNTMATCHES, like you proposed initially, would get us to the solution.


It sounds like using "COUNTIFS(Table 1::A,"",Table 1::B,"")" in addition to COUNTA and a regex check, as I described in response to Badunit earlier, would also work. I'm curious which of these two methods is more efficient.

Jun 20, 2023 2:13 PM in response to PuddleOfFat

PuddleOfFat wrote:

Please correct me if I'm wrong but from here, by using this in addition to "COUNTIFS(Table 1::A,"",Table 1::B,"")" this should work flawlessly to detect two adjacent blanks while also making sure that null strings ("") do not throw off the data, correct?


Expanding on this: here is a formula I came up with that incorporates all of these ideas above. It seems to work exactly as intended:


=IF(COUNTA(A:B)=COUNTIFS(A:B,REGEX("\d{1,3}((\,\d{3})+)*\.\d{2}",case-sensitive)),IF(COUNTIFS(A,"",B,"")>0,"Error: there are adjacent blanks","Perfect: NO adjacent blanks"),"Error: there is a hidden null string or incorrectly formatted number")


SGIII’s idea of TEXTJOIN and COUNTMATCHES also works. I’m curious which of these two approaches would be more efficient and reliable.

Jun 19, 2023 10:18 PM in response to SGIII

This is brilliant! I have been playing around with this and I discovered a flaw, though: the regex can trigger a false error. If there is a value in Column A and a value in Column B in the row below that, the regex will incorrectly result in an error, thinking there are two adjacent blanks. This is because, for example, A1=has_value, B1=blank, A2=blank, B2=has_value. Thus, the regex finds two blanks consecutively, thinking they're adjacent. However, if there is a value in Column B and two adjacent blank cells in the row below that, then a value in Column A in the row below those two blanks, the regex would also result in "~~~" which correctly identifies two blanks.


The formula used on the table above:

=TEXTJOIN("~",0,Table 1::A:B)


which results in:

2.99~~4,000.00~~2.99~~~51.99~0.01~~~60.00~43.39~~~25.00~257.69~~~~~~~50.00~1.00~40.00~~~942.96~


In the table above, the two blank cells in B3 & A4 will result in "~~~" which would incorrectly trigger an error:

2.99~~4,000.00~~2.99~~~51.99~0.01~~~60.00~43.39~~~25.00~257.69~~~~~~~50.00~1.00~40.00~~~942.96~

From B13-A15, though, the regex would correctly trigger an error from the two adjacent blanks:

2.99~~4,000.00~~2.99~~~51.99~0.01~~~60.00~43.39~~~25.00~257.69~~~~~~~50.00~1.00~40.00~~~942.96~


So I have been playing around with different ways of trying to fix this.

I tried creating a regex that knows where each row ends- in this case, every second "~". I came up with the following (bulky but working) regex:

(?:\d{1,3}(?:(?:\,\d{3})+)*\.\d{2})?~(?:\d{1,3}(?:(?:\,\d{3})+)*\.\d{2})?(~)

I should specify that the numerical data in my table will always have the same format: 1.00 / 100.00 / 1,000.00 / etc. - hence why I am using "(?:\d{1,3}(?:(?:\,\d{3})+)*\.\d{2})" in my regex to match the number values. Anyways, the regex matches every 2nd "~" and groups them into Group 1. I'd like to try to replace all the matched "~"s in Group 1 with a comma, so that I could ultimately have a joined text that joins the two values in every row in the table with a "~" between them but a comma that separates each row. It would look like this: "[A1]~[B1],[A2]~[B2]," etc... From there, I can use a regex to easily check if there are two adjacent blanks in the same row, since the regex would know where the rows begin and end. This is where I got stumped and couldn't figure out how to achieve that, whether through regex or formulas...

I also tried using TEXTJOIN on the individual columns to get two separate strings:

For Column A: 2.99~4,000.00~2.99~~0.01~~43.39~~257.69~~~~1.00~~942.96

For Column B: ~~~51.99~~60.00~~25.00~~~~50.00~40.00~~

From there, I was thinking I could somehow group together the Nth value from each, with each row separated by a comma. Effectively trying to achieve the same thing as above but by a different means. Again, I was stumped by this as well.

I also tried some other methods that I don't think will lead to a solution, so I will spare you the reading time lol. All in all, I'm not sure if I'm approaching this problem correctly but here is where I'm at.

Jun 20, 2023 7:53 AM in response to PuddleOfFat

I get tangled up in the REGEX but there

PuddleOfFat wrote:

This is brilliant! I have been playing around with this and I discovered a flaw, though: the regex can trigger a false error. If there is a value in Column A and a value in Column B in the row below that, the regex will incorrectly result in an error, thinking there are two adjacent blanks. This is because, for example, A1=has_value, B1=blank, A2=blank, B2=has_value. Thus, the regex finds two blanks consecutively, thinking they're adjacent. However, if there is a value in Column B and two adjacent blank cells in the row below that, then a value in Column A in the row below those two blanks, the regex would also result in "~~~" which correctly identifies two blanks.


https://discussions.apple.com/content/attachment/1b8cf475-50b8-40a5-9963-db91369bab3c


I tried creating a regex that knows where each row ends


Yes that seems to be important. I get tangled up in the regex and haven't had a chance to try more but I'm thinking there may be an easier solution if you add a third column and fill it with a character you wouldn't be using otherwise (perhaps a ^) and then apply TEXTJOIN to A:C, giving you a string like this to work with:


2.99~~^~4,000.00~~^~2.99~~^~~51.99~^~0.01~~^~~60.00~^~43.39~~^~~25.00~^~~~~~~~~50.00~~1.00~40.00~~~~~942.96~~


SG




Jun 15, 2023 11:21 PM in response to PuddleOfFat

Here's an example that monitors the cells in columns B and C, and returns these numbers:

  • 1 if the cell in column B has content and the cell in the same row of C is empty,
  • 2 if the cell in column B is empty and the cell in the same row of C has content,
  • 3 if both the cell in column B and the cell in column C have content, and
  • 0 if both the cell in this row of column B and the cell in this row of column C are empty.


The formula, shown below the table, is entered in the column D cell on the row containing the first pair of cells to be tested (Row ? in the example), and filled down to the last row to be tested.



Regards,

Barry

Jun 20, 2023 5:00 AM in response to PuddleOfFat

Also, as with the COUNTIFS formula I provided, TEXTJOIN with the FALSE parameter gives the same result for "" or blank cells. If you need them to be absolutely blank, you may need to use a column of formulas to check each row individually with AND(ISBLANK(A),ISBLANK(B)).


I notice that TEXTJOIN with the TRUE parameter will skip over blank cells but will include cells with "". Maybe that can be used...

Jun 21, 2023 5:03 AM in response to SGIII

I wish I had an older version of Numbers to go back in time and see if I am recalling correctly. I could have sworn that COUNTIF(B2,"") would count a cell with "" in it or if the cell was blank. It does in Excel. Do you recall differently?


COUNTIF, COUNTIFS, SUMIF, and SUMIFS all work the same in Numbers ("" means blank, not ""). In Excel they all work like they do in Excel ("" means "" or blank). A spreadsheet that uses any of these functions this way cannot be imported into Numbers or exported to Excel and work correctly.


The formula IF(B2="",TRUE,FALSE) returns TRUE if B2 has either "" or is blank. This is inconsistent with how those other functions work.


As a side note, COUNTIF(B2,REGEX("^$")) counts null strings AND blank cells but REGEX is not supported in Excel so this would be useless for export.

Jun 20, 2023 5:38 PM in response to PuddleOfFat

I am confused. I could have sworn that COUNTIFS(A,"",B,"") counted rows with adjacent "", adjacent blanks, or combinations of them. I could swear I tried every combination of filled, "" and blank cells and it was treating "" and blank the same. Now I try it and it will only count the rows where both cells are actually blank. Well, that is what you wanted so I guess it worked out alright.


Now I am wondering how to count cells that have a null string. I am wondering if Apple changed something. Excel considers "" and blank to be the same with this formula. I recall that it worked that way in Numbers, too, but I guess I could be wrong.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to find if cell adjacent to a blank cell is also blank?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.