ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Mulipule Columns & VBA (https://www.excelbanter.com/excel-discussion-misc-queries/179724-mulipule-columns-vba.html)

Excel 2007 - SPB

Mulipule Columns & VBA
 
I have a series of columns I wish to hide, these change depending on the
report selected
VBA refers to F18 on sheets1 and changes dependent on the report selected
code is;
Sheets(2).Select
Columns("V:AB").Select ' Resets all columns
Selection.EntireColumn.Hidden = False

colhide = sheets(1).range("F18")
Sheets(2).Select
Columns(colhide).Select
Selection.EntireColumn.Hidden = True

This works if the Columns are a continious block ie. F18 = "B;F"
but fails if F18="B:B,F:AA,AC:AC"

Any ideas

Mike H

Mulipule Columns & VBA
 
Hi,

Try this in F18
V:V,W:W,X:X,Y:Y,Z:Z,AA:AA,AB:AB, AF:AF

and you may find this a little better

Sub ordinate()
colhide = Sheets(1).Range("F18")
Sheets(2).Select
Range(colhide).EntireColumn.Hidden = True
End Sub

Mike

"Excel 2007 - SPB" wrote:

I have a series of columns I wish to hide, these change depending on the
report selected
VBA refers to F18 on sheets1 and changes dependent on the report selected
code is;
Sheets(2).Select
Columns("V:AB").Select ' Resets all columns
Selection.EntireColumn.Hidden = False

colhide = sheets(1).range("F18")
Sheets(2).Select
Columns(colhide).Select
Selection.EntireColumn.Hidden = True

This works if the Columns are a continious block ie. F18 = "B;F"
but fails if F18="B:B,F:AA,AC:AC"

Any ideas


Excel 2007 - SPB

Mulipule Columns & VBA
 
Works Great

Thanks I knew it would be simple

"Mike H" wrote:

Hi,

Try this in F18
V:V,W:W,X:X,Y:Y,Z:Z,AA:AA,AB:AB, AF:AF

and you may find this a little better

Sub ordinate()
colhide = Sheets(1).Range("F18")
Sheets(2).Select
Range(colhide).EntireColumn.Hidden = True
End Sub

Mike

"Excel 2007 - SPB" wrote:

I have a series of columns I wish to hide, these change depending on the
report selected
VBA refers to F18 on sheets1 and changes dependent on the report selected
code is;
Sheets(2).Select
Columns("V:AB").Select ' Resets all columns
Selection.EntireColumn.Hidden = False

colhide = sheets(1).range("F18")
Sheets(2).Select
Columns(colhide).Select
Selection.EntireColumn.Hidden = True

This works if the Columns are a continious block ie. F18 = "B;F"
but fails if F18="B:B,F:AA,AC:AC"

Any ideas



All times are GMT +1. The time now is 02:27 PM.

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