Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-29-2025, 04:43 AM
MartinGM MartinGM is offline Can a cell be both blank and not blank ? Windows 11 Can a cell be both blank and not blank ? Office 2021
Competent Performer
Can a cell be both blank and not blank ?
 
Join Date: May 2023
Location: England
Posts: 101
MartinGM is on a distinguished road
Default Can a cell be both blank and not blank ?


I have been having problems with a large workbook which I have tracked down to an odd behaviour where a cell seems to be both blank and not blank !

There is a named range, let's call it GreenBox, and to illustrate the issue I have used two ways of calculating how many cells it contains:

The first method multiplies the number of rows by the number of columns - and gives the correct result:
=ROWS(GreenBox)*COLUMNS(GreenBox)

The second method sums the number of filled cells and the number of blank cells and gives a number of cells that is 1 greater then the first method:
=COUNTA(GreenBox)+COUNTBLANK(GreenBox)

I finally pinpointed the issue when I found one cell which returns a value of 1 from COUNTA and a value of 1 from COUNTBLANK.

I can't see how this is possible ?

If I copy the offending cell into another part of the GreenBox range, the discrepancy rises to 2 - as I would expect. No contents are visible in the offending cell and deleting its contents makes no difference. But erasing the cell completely with Clear All sorts out the discrepancy.

The discrepancy arises from time to time - I have no idea how - and I would like to undertand what is going on so that I can stop it from happening.

I have a small workbook which illustrates the issue but I can't attach it here because it has a lot of personal customisation in the ribbon which gives away personal information. I would post it if I could find a way of making this one workbook have no customisation.

Appreciate any help / ideas.
Reply With Quote
  #2  
Old 03-29-2025, 04:56 AM
MartinGM MartinGM is offline Can a cell be both blank and not blank ? Windows 11 Can a cell be both blank and not blank ? Office 2021
Competent Performer
Can a cell be both blank and not blank ?
 
Join Date: May 2023
Location: England
Posts: 101
MartinGM is on a distinguished road
Default Further information

I have discovered that if I select the offending cell, click in the formula bar and then click on return the discrepancy disappears.

That doesn't make sense to me either.

I have also checked the LEN function which returns 0.
Reply With Quote
  #3  
Old 03-29-2025, 07:03 AM
Pecoflyer's Avatar
Pecoflyer Pecoflyer is offline Can a cell be both blank and not blank ? Windows 11 Can a cell be both blank and not blank ? Office 2021
Expert
 
Join Date: Nov 2011
Location: Brussels Belgium
Posts: 2,920
Pecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond repute
Default

Your cell probably contains an empty text string (""), which will return 1 with both functions. Depending on what you have in the other cells there are ways to ignore that. Please post a sample sheet with some data and manually mocked up results if needed
To check if A1, say, has an empty text string, type =TYPE(A1) somewhere. If the result is 2, it is text.
Now, how did it get there ?
__________________
Using O365 v2503 - Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post
Reply With Quote
  #4  
Old 03-29-2025, 11:29 AM
Logit Logit is offline Can a cell be both blank and not blank ? Windows 10 Can a cell be both blank and not blank ? Office 2007
Expert
 
Join Date: Jan 2017
Posts: 587
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

The following will remove all 'empty' cells in your workbook. Test on a COPY OF YOUR WORKBOOK for safety reasons. Test for file size before then after running macro.

Code:
Sub LipoSuction()
'JBeaucaire (8/3/2009)
Dim LR As Long, LC As Long
Dim ws As Worksheet

For Each ws In Worksheets
    LR = ws.Range("A" & ws.Rows.Count).End(xlUp).Row + 1
    LC = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column + 1

    'Clear everything below column A last cell and row 1 last cell
        ws.Range(ws.Cells(1, LC), ws.Cells(ws.Rows.Count, ws.Columns.Count)).Delete
        ws.Range(ws.Cells(LR, 1), ws.Cells(ws.Rows.Count, ws.Columns.Count)).Delete
Next ws

End Sub
Reply With Quote
  #5  
Old 03-29-2025, 09:41 PM
MartinGM MartinGM is offline Can a cell be both blank and not blank ? Windows 11 Can a cell be both blank and not blank ? Office 2021
Competent Performer
Can a cell be both blank and not blank ?
 
Join Date: May 2023
Location: England
Posts: 101
MartinGM is on a distinguished road
Default It IS an empty string

Quote:
Originally Posted by Pecoflyer View Post
Your cell probably contains an empty text string (""), which will return 1 with both functions. Depending on what you have in the other cells there are ways to ignore that. Please post a sample sheet with some data and manually mocked up results if needed
To check if A1, say, has an empty text string, type =TYPE(A1) somewhere. If the result is 2, it is text.
Now, how did it get there ?
Type(XXX) does return 2. Very helpful, thank you.
There are lots of other TEXT cells on the worksheet but they all contain text, so they return 0 for the COUNTBLANK function.
That gives me enough clues to write a procedure to identify any cells with the empty text string. I'll do that in VBA as it is a very large worksheet.
I too wonder how these empty strings crop up from time to time - not often though.
Thanks again
Martin
Reply With Quote
  #6  
Old 03-29-2025, 09:44 PM
MartinGM MartinGM is offline Can a cell be both blank and not blank ? Windows 11 Can a cell be both blank and not blank ? Office 2021
Competent Performer
Can a cell be both blank and not blank ?
 
Join Date: May 2023
Location: England
Posts: 101
MartinGM is on a distinguished road
Default

Quote:
Originally Posted by Logit View Post
The following will remove all 'empty' cells in your workbook. Test on a COPY OF YOUR WORKBOOK for safety reasons. Test for file size before then after running macro.

Code:
Sub LipoSuction()
'JBeaucaire (8/3/2009)
Dim LR As Long, LC As Long
Dim ws As Worksheet

For Each ws In Worksheets
    LR = ws.Range("A" & ws.Rows.Count).End(xlUp).Row + 1
    LC = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column + 1

    'Clear everything below column A last cell and row 1 last cell
        ws.Range(ws.Cells(1, LC), ws.Cells(ws.Rows.Count, ws.Columns.Count)).Delete
        ws.Range(ws.Cells(LR, 1), ws.Cells(ws.Rows.Count, ws.Columns.Count)).Delete
Next ws

End Sub
Thanks, but that isn't addressing my issue. Your procedure clears cells outside the "used" area. My "problem" cell(s) is within the used area.

See my reply to PECOFLYER

Cheers

Martin
Reply With Quote
  #7  
Old 03-30-2025, 01:26 AM
Pecoflyer's Avatar
Pecoflyer Pecoflyer is offline Can a cell be both blank and not blank ? Windows 11 Can a cell be both blank and not blank ? Office 2021
Expert
 
Join Date: Nov 2011
Location: Brussels Belgium
Posts: 2,920
Pecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond repute
Default

A small Power Query solution will clean that up.
Text is highlighted in yellow. After transformation, the null string has disappeared


Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Replaced Value" = Table.ReplaceValue(Source,"",null,Replacer.ReplaceValue,Table.ColumnNames(Source))
in
    #"Replaced Value"
Attached Files
File Type: xlsx No Null Strings.xlsx (17.8 KB, 1 views)
__________________
Using O365 v2503 - Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post
Reply With Quote
  #8  
Old 03-30-2025, 01:45 AM
MartinGM MartinGM is offline Can a cell be both blank and not blank ? Windows 11 Can a cell be both blank and not blank ? Office 2021
Competent Performer
Can a cell be both blank and not blank ?
 
Join Date: May 2023
Location: England
Posts: 101
MartinGM is on a distinguished road
Default

Quote:
Originally Posted by Pecoflyer View Post
A small Power Query solution will clean that up.
Text is highlighted in yellow. After transformation, the null string has disappeared


Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Replaced Value" = Table.ReplaceValue(Source,"",null,Replacer.ReplaceValue,Table.ColumnNames(Source))
in
    #"Replaced Value"
Thanks again
I couldn't work out how to detect the errant cell in "pure" VBA but a simple use of the Worksheet functions did the trick - here's the critical line

Code:
If Application.CountA(Cell) = 1 And Application.CountBlank(Cell) = 1 Then
Now to find out how this happens

Martin
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
IF cell in Col A is populated BUT cell in Col C is blank DELETE ROW ChrisOK Excel Programming 7 05-05-2019 09:00 PM
Can a cell be both blank and not blank ? Fill blank cell with value from adjacent cell kevinbradley57 Excel Programming 2 04-17-2018 08:40 AM
Can a cell be both blank and not blank ? Formulato say if cell is blank do this, if not blank do this. mbesspiata Excel 1 01-17-2015 05:02 AM
Can a cell be both blank and not blank ? not showing blank cell alw Excel 4 03-13-2014 01:08 PM
Can a cell be both blank and not blank ? How to turn all blank lines into non-blank for legal forms sieler Word 3 04-12-2009 01:38 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:08 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft