Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hide a column based on cells value

I'm famailar with VBA and some aspects of macro in MS applications, not as much in Libreoffice. I have a sheet with about 12 or so columns. I need to have hide cells based on the value in the cell. Currently, I have it set up with a list using Validity. It is the list of months. I would like to hide or show columns associated with the particular month. Say, I select Feb in cell A1 and columns B, D, E, F etc... hide and column C has no change (the column for Feb).

First I thought I would set up a simple macro that hides cells and I would try to re-code it to do what I needed, then fiddle with it until I got the hide and show features, suspect lots of if then statements. I could have a button for each month with it's own macro, but not the best option.

This is what I have so far.

sub Hide2
dim document   as object
dim dispatcher as object
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("")
dispatcher.executeDispatch(document, ".uno:HideColumn", "", 0, Array())
end sub

I found this on this forum, kinda what I need, but based on rows, was going to replace rows with colums.

Sub MyDoLoop
Dim oCell as Object, oSheet as Variant, oSheets as Variant, oString as String
oSheets = ThisComponent.getSheets(0)
oSheet = oSheets.getByIndex(0)
oRows = oSheet.Columns
oRow = oRows.GetByIndex(0)
oCell = oSheet.GetCellByPosition(0, 0)
oString = oCell.getString()
If oString = "Hello" Then
oRow.IsVisible = False
oRow.IsVisible = True
End If
End Sub