Most valuable professional
  • Hot Topics

Excel Hide a number of columns depends of a cell vaue

Hello all , I have a problem with a code. I want to hide a number of columns, according to a value of a cell. If value is ='1' unhide "E:K" and hide "E:K". If value is ='2' unhide "E:K" and hide "F:K" If value is ='3' unhide "E:K" and hide "G:K" . . If value is ='7' unhide "E:K" and hide "K" I tried something but i have a problem. It works if i select value fom 1 to 8 but if i make a copy and paste i receive an error (the columns are hide and unhide correctly). Run-time error '13': Type mismatch. The code is below: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column = 3 And Target.Row = 3 And Target.Value = "1" Then Application.Columns("E:K").Select Application.Selection.EntireColumn.Hidden = False Application.Columns("E:L").Select Application.Selection.EntireColumn.Hidden = True ElseIf Target.Column = 3 And Target.Row = 3 And Target.Value = "2" Then Application.Columns("E:K").Select Application.Selection.EntireColumn.Hidden = False Application.Columns("F:K").Select Application.Selection.EntireColumn.Hidden = True ElseIf Target.Column = 3 And Target.Row = 3 And Target.Value = "3" Then Application.Columns("E:K").Select

This question generated 9 answers. To proceed to the answers, click here.

This thread is current as of February 11, 2018.

For more resources for Microsoft Excel:

This article includes the following tags:

  • Excel
  • Microsoft Excel