0

I am trying to use the functions below to hide columns

Function SCPArgsShowOnly() As Boolean
    Dim sColsToHide As String
    sColsToHide = "E:I,M:N"
    hideCols sColsToHide
    SCPArgsShowOnly = True
End Function

'======================================================
Sub hideCols(sCols As String)
    Dim sTemp() As String, allCols As String
    sTemp = Split(sCols, ",")
    allCols = "A:N"

    With Sheets("Functions")
        .Columns(allCols).Hidden = False

        For i = LBound(sTemp) To UBound(sTemp)
            .Columns(sTemp(i)).Hidden = True
        Next
    End With
End Sub

It works fine when I run it through the debugger window. But it only returns true when I use it in a cell like this = SCPArgsShowOnly()

What am I missing?

Quintin Balsdon
  • 5,484
  • 10
  • 54
  • 95
S.aad
  • 518
  • 1
  • 5
  • 22

1 Answers1

2

Excel does not allow calling functions that DO something from a cell.
Only functions that just return a value can be used, and that seems quite logical.
Imagine your columns appearing or disappearing whenever an entry in the sheet triggers a recalc ?

iDevlop
  • 24,841
  • 11
  • 90
  • 149