ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hiding Columns (https://www.excelbanter.com/excel-programming/350900-hiding-columns.html)

Andy the Yeti

Hiding Columns
 
Is there a piece of VBA code that will allow me to run a macro at a push of a
button that will hide or unhide columns in a workbook dependant on a given
criteria in say row A ?
For example if columns A, B, C & F, & H has a €œ1€ in then leave and if
columns D, E, & G has a €œ2€ then €˜hide ?

Many thanks

Andy


RC-

Hiding Columns
 
Sub HideColumns()

Range("A1").Select
Do Until ActiveCell.Value = ""
If ActiveCell.Value = 2 Then
Selection.EntireColumn.Hidden = True
End If

ActiveCell.Offset(ColumnOffset:=1).Activate
Loop

Range("A1").Select

End Sub

HTH
RC-

"Andy the yeti" wrote in message
...
Is there a piece of VBA code that will allow me to run a macro at a push
of a
button that will hide or unhide columns in a workbook dependant on a given
criteria in say row A ?
For example if columns A, B, C & F, & H has a "1" in then leave and if
columns D, E, & G has a "2" then 'hide' ?

Many thanks

Andy




N10

Hiding Columns
 
Hi
This might be a little faster for you

Sub Hidetwo()


Application.ScreenUpdating = False

Dim task As Range
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Set task = Selection
For Each cell In task
If cell.Value = "2" Then cell.EntireColumn.Hidden = True
Next
Application.ScreenUpdating = True


End Sub

"RC-" wrote in message
...
Sub HideColumns()

Range("A1").Select
Do Until ActiveCell.Value = ""
If ActiveCell.Value = 2 Then
Selection.EntireColumn.Hidden = True
End If

ActiveCell.Offset(ColumnOffset:=1).Activate
Loop

Range("A1").Select

End Sub

HTH
RC-

"Andy the yeti" wrote in message
...
Is there a piece of VBA code that will allow me to run a macro at a push
of a
button that will hide or unhide columns in a workbook dependant on a
given
criteria in say row A ?
For example if columns A, B, C & F, & H has a "1" in then leave and if
columns D, E, & G has a "2" then 'hide' ?

Many thanks

Andy






Andy the Yeti

Hiding Columns
 
thank you both !!



"N10" wrote:

Hi
This might be a little faster for you

Sub Hidetwo()


Application.ScreenUpdating = False

Dim task As Range
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Set task = Selection
For Each cell In task
If cell.Value = "2" Then cell.EntireColumn.Hidden = True
Next
Application.ScreenUpdating = True


End Sub

"RC-" wrote in message
...
Sub HideColumns()

Range("A1").Select
Do Until ActiveCell.Value = ""
If ActiveCell.Value = 2 Then
Selection.EntireColumn.Hidden = True
End If

ActiveCell.Offset(ColumnOffset:=1).Activate
Loop

Range("A1").Select

End Sub

HTH
RC-

"Andy the yeti" wrote in message
...
Is there a piece of VBA code that will allow me to run a macro at a push
of a
button that will hide or unhide columns in a workbook dependant on a
given
criteria in say row A ?
For example if columns A, B, C & F, & H has a "1" in then leave and if
columns D, E, & G has a "2" then 'hide' ?

Many thanks

Andy







JMC

Hiding Columns
 
Hi N10,

This code works great, but it only works on the worksheet I'm currently
viewing. How could I get to do the entire workbook (approx. 85 worksheets)?

"N10" wrote:

Hi
This might be a little faster for you

Sub Hidetwo()


Application.ScreenUpdating = False

Dim task As Range
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Set task = Selection
For Each cell In task
If cell.Value = "2" Then cell.EntireColumn.Hidden = True
Next
Application.ScreenUpdating = True


End Sub

"RC-" wrote in message
...
Sub HideColumns()

Range("A1").Select
Do Until ActiveCell.Value = ""
If ActiveCell.Value = 2 Then
Selection.EntireColumn.Hidden = True
End If

ActiveCell.Offset(ColumnOffset:=1).Activate
Loop

Range("A1").Select

End Sub

HTH
RC-

"Andy the yeti" wrote in message
...
Is there a piece of VBA code that will allow me to run a macro at a push
of a
button that will hide or unhide columns in a workbook dependant on a
given
criteria in say row A ?
For example if columns A, B, C & F, & H has a "1" in then leave and if
columns D, E, & G has a "2" then 'hide' ?

Many thanks

Andy








All times are GMT +1. The time now is 01:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com