Insert column and hide columns

R

Rob

I need to hide a number of columns in a sheet and have used Columns
("C:C").EntireColumn.Hidden = True. This is fine but I have 15 columns to
hide and having 15 rows of code seems excessive. Is there a way to declare
the columns and thus apply in less rows of code?

Also, have similar issue with inserting where to say I want to insert 3
rows, I have 3 rows of code.

Thanks, Rob
 
G

Gary Keramidas

you could try something like this

Sub hide_columns()
Dim arr As Variant
Dim i As Long
arr = Array("c:c", "e:e", "h:h", "m:m")
For i = LBound(arr) To UBound(arr)
Columns(arr(i)).EntireColumn.Hidden = True
Next
End Sub
 
R

Rob

Thanks Gary, Am I correct to think that inserting rows or columns would
work the same way?

Regards, Rob
 
F

Francois via OfficeKB.com

Rob said:
I need to hide a number of columns in a sheet and have used Columns
("C:C").EntireColumn.Hidden = True. This is fine but I have 15 columns to
hide and having 15 rows of code seems excessive. Is there a way to declare
the columns and thus apply in less rows of code?

Also, have similar issue with inserting where to say I want to insert 3
rows, I have 3 rows of code.

Thanks, Rob
Or:-
("C:Z").EntireColumn.Hidden = True.
 
R

Rob

Francois, thanks however the columns aren't concurrent, eg I want to hide c,
e, m, j, x

Regards, Rob
 
P

Patrick Molloy

Range("C:C,F:H,J:J,P:T").EntireColumn.Hidden = True

Rob said:
Francois, thanks however the columns aren't concurrent, eg I want to hide c,
e, m, j, x

Regards, Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top