[Solved] Macro to check for blank cells

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
cmeylaq
Posts: 34
Joined: Wed Apr 19, 2023 3:52 pm

[Solved] Macro to check for blank cells

Post by cmeylaq »

Hi guys...need your assistance...below and attached is a macro to return "ALL Good" if cells B1 B2 and B3 IS NOT BLANK.
If any of these are BLANK then it should return the respective message.
The below is always returning "ALL GOOD" even when the cells are blank.

Any help is much appreciated.

Code: Select all


Sub checkforblanks
sheet = ThisComponent.CurrentController.ActiveSheet
TimeFrom = sheet.getCellRangeByName("B1").value
TimeTo = sheet.getCellRangeByName("B2").value
AttName = sheet.getCellRangeByName("B3").value

If Timefrom = "" then 
Msgbox "Update Time From" 
else
If Timeto = "" then 
Msgbox "Update Time To" 
else
If AttName = "" then 
Msgbox "Update Attendant Name" 
else msgbox  "All Good" 
Endif
Endif
Endif

End Sub


Attachments
Untitled 2.ods
(9.34 KiB) Downloaded 68 times
Last edited by MrProgrammer on Mon May 01, 2023 3:14 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
OpenOffice 3.1 on Windows Vista
JeJe
Volunteer
Posts: 2778
Joined: Wed Mar 09, 2016 2:40 pm

Re: Macro to check from blank cells

Post by JeJe »

This is exactly the same question as your last post. change .value to .string.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
cmeylaq
Posts: 34
Joined: Wed Apr 19, 2023 3:52 pm

Re: Macro to check from blank cells

Post by cmeylaq »

Thank you JeJe. Apologies :(
OpenOffice 3.1 on Windows Vista
User avatar
MrProgrammer
Moderator
Posts: 4902
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Macro to check from blank cells

Post by MrProgrammer »

Learn how to use breakpoints and the Watch window so you can discover for yourself that the value of an empty cell is zero. Or search the forum for information on how to use object inspectors like MRI and Xray. Attempting to write macros without these tools is effectively impossible. A SELECT statement (instead of IF) will simplify your macro,
202304241201.gif
202304241201.gif (103.87 KiB) Viewed 1407 times

If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
User avatar
Lupp
Volunteer
Posts: 3548
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Macro to check from blank cells

Post by Lupp »

The question explicitly asked how to check cells for being BLANK. Neither a cell having the .Value 0 nor one with empty .String can be assured to be BLANK. A BLANK cell may be formatted, but must not contain anything. This includes that a cell containing a formula returning the result "" (empty string) is not BLANK. The standard function ISBLANK() asked for the state of such a cell will return FALSE.

A macro needing to check a cell object, say oCell, for being BLANK has to use the comparison oCell.Type=0
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
cmeylaq
Posts: 34
Joined: Wed Apr 19, 2023 3:52 pm

Re: Macro to check from blank cells

Post by cmeylaq »

thank you all for your input. much appreciated.
OpenOffice 3.1 on Windows Vista
Post Reply