Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 471
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 471
Default 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?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default 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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding variable number of columns fabio Excel Worksheet Functions 8 May 23rd 10 07:30 AM
sum number of columns based on variable value rt10516 Excel Discussion (Misc queries) 4 November 8th 07 01:47 PM
HIDING A VARIABLE NUMBER OF COLUMNS [email protected] Excel Programming 1 February 15th 07 09:14 PM
select columns by variable Jack Excel Programming 4 November 29th 05 09:09 PM
adding variable number of columns confused Excel Worksheet Functions 5 September 23rd 05 10:09 AM


All times are GMT +1. The time now is 04:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"