marreco
Member
I have a cell that want it monitored since the opening of the file is the B6
If B6 equal to 3, I would like to hide the Q column to column T
If B6 equal to 4 or would like to hide the columns U to X column
And so on, where it increases the value of B6 hide in every 4 columns
I need dinamic code.
How do it, without insert fomula in sheet. (my sheet has values in first columns)
If B6 equal to 3, I would like to hide the Q column to column T
If B6 equal to 4 or would like to hide the columns U to X column
And so on, where it increases the value of B6 hide in every 4 columns
I need dinamic code.
How do it, without insert fomula in sheet. (my sheet has values in first columns)
Code:
Option Explicit
Sub HiddenColumns()
Dim c As Integer
Dim cel As Range
Dim rng As Range
Set rng = Range("D1:AWZ1")
[Q1].Formula = "=INT((COLUMNS($A1:A1)-1)/4)+1"
Range("Q1").AutoFill Destination:=Range(Cells(1, 17), Cells(1, 1300))
Range("Q1").Resize(, 1300).Value = Range("Q1").Resize(, 1300).Value
If [B6].Value <> "" Then
c = [B6].Value - 2
For Each cel In rng
If cel.Value = c Then
cel.EntireColumn.Hidden = True
End If
Next cel
End If
rng.ClearContents
End Sub