Unable to hide a cell from printing using macro

I want to hide 2 cells (Which contain say discount and discount %) from printing ( not make them invisible) when discount percentage is 0 using a macro is 0. Here is the code I have used:

        rem before this is some other code

         If DiscPercent.getValue = 0 Then
		Disc.CellProtection.isPrintHidden = True
		DiscPercent.CellProtection.isPrintHidden = True
		Print DiscPercent.CellProtection.isPrintHidden
	Else
		Disc.CellProtection.isPrintHidden = False
		DiscPercent.CellProtection.isPrintHidden = False
End If

The trouble is that the isPrintHidden property is not getting set and I don’t know why. I am only able to change this property from the calc UI and I wrote a dummy macro to verify this. Is this property a read only property?? Am I missing something??

Thanks

In short:

cp = cell.CellProtection  
cp.IsPrintHidden = True  
cell.CellProtection = cp     

There are properties of structured types which only can be set by assigning a new “value” of the structure as a whole. This is similar to the way you need to handle some array-properties of cell ranges (DataArray e.g).
From memory I would say that this is not a concept consistently applied to all structured properties.

BTW: You can even hide cells from printig by ConditionalFormatting. This may in some cases help to avoid macro programming.
===Edit 2020-07-31 about 09:30 UTC===
Concerning the usage of CF see this example: (deleted)
===Edit shortly after===
The uploaded example had a little flaw concerning a comment on merging. The attachment below should fix this.
ask257890conditionallyHideWhenPrinting.ods

Thank you very much @Lupp. It worked. I did not know that I needed to overwrite the value of the structure itself. I will also investigate using the conditional formatting option.

Thanks for the example on conditional formatting. I will look into i for further clarity

I tried using conditional formatting and it was a way better solution than the macro. Thanks for the advice @Lupp .