Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello @Dennis1234,

in writing a macro involving months, it would be better to work with the month number instead of local month names. For this purpose it is assumed here below that your cell A2 contains the month number ( = 2 ) that corresponds to your month name ( ="Feb" ) in cell A1.

In that case you could write the following formula into any unused cell:

=HIDECOLUMNSEXCEPT(1;12;A2)

using the Basic function:

Function hideColumnsExcept( lColumnStart As Long, lColumnEnd As Long, lColumnExcept As Long )
REM Hides a range of Columns except one Column in the currently active Sheet.
REM CALC FORMULA : =HIDECOLUMNSEXCEPT(1;12;2)   REM Hides columns B to M except C.
    Dim i As Long
    For i = lColumnStart To lColumnEnd
        ThisComponent.CurrentController.ActiveSheet.Columns.getByIndex( i ).IsVisible = ( i = lColumnExcept )
    Next i
End Function