Create variables in an Excel template that track section columns using VBA

Whenever I want to add new columns to a template, I need to change a few values ​​to fit the “buttons”.

Property Get slp_hide_col() As String
slp_hide_col = "L:T"
End Property
*Seperate from the above code*    
 Private Sub SLP_Config_Click()
With Columns(slp_hide_col)
    .Select
    .EntireColumn.Hidden = Not .EntireColumn.Hidden
End With
  End Sub

I wanted to move slp_hide_col to the value of each added column. Anything that could help thanks

+2
source share
1 answer

You can create a named range for L:T. After adding new columns of named range shifts.

Then you can use it as follows:

Property Get slp_hide_col() As String
   slp_hide_col = "myNamedRange"
End Property

and then change Columns(slp_hide_col)to Range(slp_hide_col):

Public Sub SLP_Config_Click()
    With Range(slp_hide_col)
        .Select
        .EntireColumn.Hidden = Not .EntireColumn.Hidden
    End With
End Sub

enter image description here

0
source

Source: https://habr.com/ru/post/1529466/


All Articles