ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   display only columns A to I (https://www.excelbanter.com/excel-programming/378602-display-only-columns-i.html)

John Smith

display only columns A to I
 
I want users to be able to see only columns A to I. The following
code works in the worksheet_selectionchange() but I don't want it
to execute everytime users make a change on the sheet. If I put
the code in a module, no column is visible. The sheet is
completely blank. Any help?


Sheets("sheet1").Columns.Hidden = True
Sheets("sheet1").Columns("A:I").Hidden = false
Sheets("sheet1").Columns("A:I").Show

Chip Pearson

display only columns A to I
 
Your code works fine for me.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)



"John Smith" wrote in message
...
I want users to be able to see only columns A to I. The following
code works in the worksheet_selectionchange() but I don't want it
to execute everytime users make a change on the sheet. If I put
the code in a module, no column is visible. The sheet is
completely blank. Any help?


Sheets("sheet1").Columns.Hidden = True
Sheets("sheet1").Columns("A:I").Hidden = false
Sheets("sheet1").Columns("A:I").Show




Gary''s Student

display only columns A to I
 
In a module put:

Sub Macro1()
Columns("A:IV").EntireColumn.Hidden = False
Columns("J:IV").EntireColumn.Hidden = True
End Sub


In worksheet code for sheet1 put:

Private Sub Worksheet_Activate()
Call Macro1
End Sub
--
Gary's Student


"John Smith" wrote:

I want users to be able to see only columns A to I. The following
code works in the worksheet_selectionchange() but I don't want it
to execute everytime users make a change on the sheet. If I put
the code in a module, no column is visible. The sheet is
completely blank. Any help?


Sheets("sheet1").Columns.Hidden = True
Sheets("sheet1").Columns("A:I").Hidden = false
Sheets("sheet1").Columns("A:I").Show


Don Guillett

display only columns A to I
 

How about
Sheets("sheet1").Columns("j:Iv").Hidden = True
Will need to change for xl2007 files
--
Don Guillett
SalesAid Software

"John Smith" wrote in message
...
I want users to be able to see only columns A to I. The following
code works in the worksheet_selectionchange() but I don't want it
to execute everytime users make a change on the sheet. If I put
the code in a module, no column is visible. The sheet is
completely blank. Any help?


Sheets("sheet1").Columns.Hidden = True
Sheets("sheet1").Columns("A:I").Hidden = false
Sheets("sheet1").Columns("A:I").Show




Mike Fogleman

display only columns A to I
 
Put in the Worksheet_Activate event.
Private Sub Worksheet_Activate()
Sheets("sheet1").Columns("J:IV").Hidden = True
End Sub

If they unhide the columns manually, you can re-hide them with this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Sheets("sheet1").Columns("J").Hidden = False Then
Sheets("sheet1").Columns("J:IV").Hidden = True
Else: Exit Sub
End If
End Sub

Mike F

"John Smith" wrote in message
...
I want users to be able to see only columns A to I. The following
code works in the worksheet_selectionchange() but I don't want it
to execute everytime users make a change on the sheet. If I put
the code in a module, no column is visible. The sheet is
completely blank. Any help?


Sheets("sheet1").Columns.Hidden = True
Sheets("sheet1").Columns("A:I").Hidden = false
Sheets("sheet1").Columns("A:I").Show




¤Ñ¦a¬°Äl

display only columns A to I
 
Chip Pearson wrote:

Your code works fine for me.





John Smith

display only columns A to I
 
Where did you put the code? I put it in a module and got a blank sheet,
no columns, no rows, no cells. When I followed the instruction on your
web site (BTW, a great site with good info) and progamatically put it in
workbook_activate() or worksheet_activate(), same blank sheet I got. It
only works when I put it in worksheet_selectionchange() but I think the
code should be executed only once, not every time people click on the
worksheet.

Chip Pearson wrote:

Your code works fine for me.





John Smith

display only columns A to I
 
Thanks to Don and Mike. Your suggestions work great.

Mike Fogleman wrote:

Put in the Worksheet_Activate event.
Private Sub Worksheet_Activate()
Sheets("sheet1").Columns("J:IV").Hidden = True
End Sub

If they unhide the columns manually, you can re-hide them with this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Sheets("sheet1").Columns("J").Hidden = False Then
Sheets("sheet1").Columns("J:IV").Hidden = True
Else: Exit Sub
End If
End Sub

Mike F

"John Smith" wrote in message
...


I want users to be able to see only columns A to I. The following
code works in the worksheet_selectionchange() but I don't want it
to execute everytime users make a change on the sheet. If I put
the code in a module, no column is visible. The sheet is
completely blank. Any help?


Sheets("sheet1").Columns.Hidden = True
Sheets("sheet1").Columns("A:I").Hidden = false
Sheets("sheet1").Columns("A:I").Show








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

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