How to check if cell is empty?

So I have InputBox asking user to input the line number.
How do I code to use that input number to check or to use with IF statement?

Example:
userinput = 10
go to line A10 and move right one cell to see if it’s empty,
if empty, paste the word “CHECKED”
if Not Empty(Else) I will code to have msgBox pop-up “ALREADY CHECKED”

#libreoffice-calc

The result of the InputBox “10” is a string. you must convert to numeric value.

go to line A10 and move right one cell to see if it’s empty,

A10 is not a line (is not a row), but it is a Cell. Then you can GET a cell (not needed to GO into the row and column) of the current Sheet by some API functions. You can reference the cell by its name ot position.
And then you can test if the cell is empty.

https://help.libreoffice.org/latest/en-US/text/sbasic/guide/read_write_values.html

" A macro needing to check a cell object, say oCell, for being BLANK has to use the comparison oCell.Type=0"
https://forum.openoffice.org/en/forum/viewtopic.php?t=109866

for the cases “not empty” OR “empty” the formula in B10 is:

=iF(A10<>"","ALREADY CHECKED","CHECKED")

remember: a space in A10 is “not empty”!

Once more (cf @Zizi64):

  • A10="" tests for A10 has no numeric value and the string property belonging to that cell is empty (lenght 0). Such a cell may “show” the result of the contained formula ="" or of a more complicated one resulting in an empty string.
  • To test for “completely empty” including “no formula contained” you need to use ISBLANK(A10).
  • If you have a macro with a cell object cellA10, you can test the cell for being blank by cellA10.Type=0 .
  • If you test with cellA10="" this can result in overwriting a formula inadvertently.

The “step one to the right” is ignored here as it is trivial.

1 Like