[Solved] Use Macro to toggle row visibility

Discuss the spreadsheet application
Post Reply
deeaar
Posts: 4
Joined: Fri Jul 13, 2018 3:32 am

[Solved] Use Macro to toggle row visibility

Post by deeaar »

I actually had this working but Calc deleted all my macros and now I can't find / recall how I managed it:

spread1 contains some stocktake data
spread2 has IF statements in the cells to show labels(text) and data(numbers) IF the stock items are present in spread1

So spread2 is often mostly (appears) empty if I don't need to order stock.

For ease of reading/faxing (yes, faxing!) I "Hide" the Rows that have null in a specific cell
ie. they appear empty but that's the IF <no data>, ""

Code: Select all

=IF($Stocktake_Calculator.N16="","",$Stocktake_Calculator.N16)
I had two buttons before HideEmpty and ShowAll, (maybe this one I can do again without too much fuss) but I can't get the HideAll if cell empty working.
Remembering that the cell isn't actually empty, just a formula printing/resulting in "" (nullstring)

This is my current attempt at a toggle macro

Code: Select all

oSheets = ThisComponent.getSheets()
oSheet1 = oSheets.getByName("Stocktake_Calculator")
oRows= oSheet1.getRows()
for i = 7 to 13 '1st row has index 0 so add 1 to get sheet actual
   oRow = oRows.getByIndex(i)
   oCell = oSheet1.getCellByPosition(i,2)
   If oCell.String = "x" Then
      oRow.isVisible = True
   Else
      oRow.isVisible = False
   End If
next i
Last edited by deeaar on Sun Sep 19, 2021 8:42 am, edited 1 time in total.
OpenOffice 5.1 on Linux Mint 18.3 Sylvia
deeaar
Posts: 4
Joined: Fri Jul 13, 2018 3:32 am

Re: Use Macro to toggle row visibility

Post by deeaar »

OK, stupid me had the Col, Row references backwards, <sigh>

oCell = oSheet1.getCellByPosition(i,2)
changed to
oCell = oSheet1.getCellByPosition(2,i)
OpenOffice 5.1 on Linux Mint 18.3 Sylvia
User avatar
karolus
Volunteer
Posts: 1159
Joined: Sat Jul 02, 2011 9:47 am

Re: Use Macro to toggle row visibility

Post by karolus »

please update your Signatur … AOO is somewhere near 4.1 and Libreoffice should be at least >= 6.1
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
User avatar
Lupp
Volunteer
Posts: 3548
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Use Macro to toggle row visibility

Post by Lupp »

karolus wrote:please update your signature … AOO is somewhere near 4.1 and LibreOffice should be at least >= 6.1
The often very useful function REGEX() only is implemented in LibO V 6.2 or higher.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
karolus
Volunteer
Posts: 1159
Joined: Sat Jul 02, 2011 9:47 am

Re: [Solved] Use Macro to toggle row visibility

Post by karolus »

@Lupp
I know REGEX … but in which Context is your Comment related to this topic ??
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
Post Reply