ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Select Variable Number of Columns (https://www.excelbanter.com/excel-programming/392892-select-variable-number-columns.html)

Mike H.

Select Variable Number of Columns
 
I want to select a variable number of columns. I know I want to start in
Column C (3) and I know how many columns out I wish to go but I can't seem to
figure out the right syntax for selecting these columns. After selection I
wish to hide them.

iCalculate

Select Variable Number of Columns
 
Hi, try this. If you want to unhide all columns just unrem
Columns.Hidden = False and run the macro.

Sub Hide_cols()
Application.ScreenUpdating = False
Dim col As Integer, i As Integer
col = Val(InputBox("Give the last column number"))
For i = 3 To col
Columns(i).Hidden = True
Next i
Application.ScreenUpdating = True
'Columns.Hidden = False
End Sub

regards


Mike H.

Select Variable Number of Columns
 
Just wondering, would the hiding routine go faster if I were to select a
range of columns to hide, rather than just one column at a time? That is
what I was originally trying to do and couldn't get it right. If you don't
think so, use what you gave me.

Another issue:
Do you know if I have cells within the column protected, I can't seem to
hide the column. Do you know how to allow protected cells to be hidden and
still be protected?


iCalculate

Select Variable Number of Columns
 
On Jul 8, 2:12 pm, Mike H. wrote:
Just wondering, would the hiding routine go faster if I were to select a
range of columns to hide, rather than just one column at a time? That is
what I was originally trying to do and couldn't get it right. If you don't
think so, use what you gave me.

Another issue:
Do you know if I have cells within the column protected, I can't seem to
hide the column. Do you know how to allow protected cells to be hidden and
still be protected?


You are right, bad habit of using iteration ;). I think this will wokr
much faster

Sub Hide_cols()
Dim col As String, i As Integer
col = CStr(InputBox("Give the last column letter"))
Range("c:" & col).Columns.Hidden = True
'Columns.Hidden = False
End Sub

as for your other question try to choose toolsprotectionprotect
worksheet and set alowance to format columns, that should do.


Dana DeLouis

Select Variable Number of Columns
 
I want to select a variable number of columns.

Hi. One way:

Sub Demo()
Dim n
n = 5

Columns(3).Resize(, n).Hidden = True
End Sub

--
HTH :)
Dana DeLouis


"Mike H." wrote in message
...
I want to select a variable number of columns. I know I want to start in
Column C (3) and I know how many columns out I wish to go but I can't seem
to
figure out the right syntax for selecting these columns. After selection
I
wish to hide them.





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

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