Checkbox visibility based on multiple criteria

I have checkboxes that are assigned to a function found in this thread:
[Checkbox visible/invisible]

Function hide_named_pushbutton1(ChkCondition as Integer, ControlName as string) as string

Dim oDoc As Object
 Dim oSheet As Object
 Dim oDrawPage As Object
 Dim oForm As Object
 Dim oControl_1 As Object

oDoc = ThisComponent
oSheet = oDoc.Sheets.getByName("TransEntry")
oDrawPage = oSheet.DrawPage 
oForm = oDrawPage.getForms().getByIndex(0)
oControl = oForm.getByName(ControlName)

  if ChkCondition = 1 then
  oControl.EnableVisible = false
  Hide_Named_ControlName = "Invisible"
  else
  oControl.EnableVisible = true 
  Hide_Named_ControlName = "Visible"
  end if

end function

[edit] Slightly edited by @Lupp to avoid "Typographical quotes" and the like. Using Preformatted text (icon </>) for code and formulas recommended. Also: Better use the semicolon as argument delimiter in formulas, It is accepte by any locale; the comma is not (though mandatory in Basic). [/edit]

I have a formula in a spreadsheet to change the value of the visibility (ChkCondition as Integer) for each checkbox. In my spreadsheet, a Transfer entry type only comes in pairs. In the first line of the pair, the checkbox must be visible, and NOT visible in the second line.

On the screenshot below, the formula works correctly if “Transfer” starts on an even row. If it starts on an odd row (the gray cells), it does not work unless the MOD(ROW(cell), 2) portion of the formula is changed to equal 1.

The formula for all cells in column H:
=IF($E8<>"Transfer", 2, IF(AND(MOD(ROW($H7), 2)=0, $H7=2,$E8="Transfer"), 1, 2))
If the formula is changed in the gray cells to following, the result is correct for those cells.
=IF($E8<>"Transfer", 2, IF(AND(MOD(ROW($H7), 2)=1, $H7=2,$E8="Transfer"), 1, 2))

I have been trying to mash these two formulae together in various ways, with no success.

Can anyone please help to make the formula work whether “Transfer” starts on an even row or an odd row.

Thanks in advance.

Thank you for your reply. Sorry about the confusion.
Version: 24.8.5.2 (X86_64) / LibreOffice Community
Build ID: fddf2685c70b461e7832239a0162a77216259f22
CPU threads: 28; OS: Windows 11 X86_64 (10.0 build 22631); UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: CL threaded

And the requested file
Checkbox Repetition.ods (16.8 KB)

upload an .ods sample here, it will be easier to spot the problem, rather than wild-guessing over screenshots and pasted code :wink:

→ This is the guide - more-details

For L12:

=IF(OR($G12<>"Transfer"; $G11<>"Transfer"); 2; IF(L11=1;2;1))

Thank you for your reply. But if this formula is copied down the column, the result is always 2.

I have modified the original uploaded worksheet to hopefully better show what I need. The formula for column I must result in the values shown in column K. The gray cells show those values that are different. I hope this helps.

Thanks to all.

Checkbox Repetition.ods (17.3 KB)

Please see attached file.
Checkbox Repetition2.ods (16.5 KB)