Ask Your Question
0

How to hide a range of rows/columns in a macro [closed]

asked 2019-12-11 12:47:44 +0200

rk874 gravatar image

updated 2020-07-21 23:20:51 +0200

Alex Kemp gravatar image

Hi, 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.e. 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.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by rk874
close date 2019-12-12 01:50:19.808377

1 Answer

Sort by » oldest newest most voted
0

answered 2019-12-11 22:31:46 +0200

updated 2019-12-11 22:36:26 +0200

Try:

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
edit flag offensive delete link more

Comments

Thank you, indeed it works

rk874 gravatar imagerk874 ( 2019-12-12 01:49:36 +0200 )edit

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?

weka gravatar imageweka ( 2020-03-21 16:25:50 +0200 )edit

Question Tools

1 follower

Stats

Asked: 2019-12-11 12:47:44 +0200

Seen: 286 times

Last updated: Dec 11 '19