How to hide a range of rows/columns in a macro

I have to assign a macro to a button which hides/shows a specific number of rows and columns having a specific index.
I insert some buttons in the sheet and theseones have to work like navigation buttons through that sheet.

I have to jump to a table located on “U230:AF241”.
The data in the sheet is in the range “A1:ED600” (I mean thoseones are the cells I’m working on).
Then it means the macro has to hide all the rows in the ranges “0 to 228”, “241 to 599” and all the columns in the ranges “A:T”, “AG:ED”.
Whilst it has to make visible all the rows in the range “229 to 240” and all the columns in the range “U:AF”.

I know how to hide/unhide single rows/columns but not ranges. I’m a novice to Basic language so if it’s possible for you to write here the code for this macro I’d appreciate it a lot.

Thanks in advance.


doc = ThisComponent
sheet = doc.CurrentController.ActiveSheet

range = sheet.getCellRangeByName("A5:A10")
range.Rows.isVisible = False

range = sheet.getCellRangeByName("B1:D1")
range.Columns.isVisible = False

Replace for your range names, and set True for show it.

If preferred Python, like me:

doc = XSCRIPTCONTEXT.getDocument()
sheet = doc.CurrentController.ActiveSheet
rango = sheet['A5:A10']
rango.Rows.IsVisible = False

rango = sheet['B1:D1']
rango.Columns.IsVisible = False

Thank you, indeed it works

I just found this thread, because I am facing a similar problem: I need a macro that can hide a range of cells, if they contain a certain string. This macro has to hide these cells (the complete rows), after a certain cell has been changed. Could you tell show me how to do this, please?