LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem Unhidding columns/rows in excel using VBA

I am having trouble with some VBA code. The goal was to write code that
would hide all columns or rows and then unhide a select few.

Here was the first attempt:
Sub UnhideCol()
With ActiveSheet
.Columns.Hidden = True 'Hide all columns
.Columns("A:B").Hidden = False 'Unhide some range of columns
End With
End Sub

The result is that all columns hidden instead of having ("A:B") unhidden.

Here is another try:
Sub UnhideCol2()
With ActiveSheet
.Range("A:B").Columns.Hidden = True
Set MyRange = .Cells.SpecialCells(xlVisible) 'MYRange("C:IV")
.Columns.Hidden = True 'Hide all columns
MyRange.Columns.Hidden = False 'Unhide MyRange("C:IV")
End With
End Sub

This successfully unhides ("C:IV").

Here is the same macro with only the range changed from ("A:B") to ("C:IV").
Sub UnhideCol2()
With ActiveSheet
.Range("C:IV").Columns.Hidden = True
Set MyRange = .Cells.SpecialCells(xlVisible) 'MYRange("A:B")
.Columns.Hidden = True 'Hide all columns
MyRange.Columns.Hidden = False 'Unhide MyRange("A:B")
End With
End Sub

The result is that all columns are hidden rather than having ("A:B") unhidden.
There seems to be a lot of inconsistency with how VBA/Excel are handling the
code.

It is even stranger with Rows:

Sub UnhideRow()
With ActiveSheet
.Rows.Hidden = True 'Hide all rows
.Rows("1:2").Hidden = False 'Unhide some range of rows
End With
End Sub

This creates a run-time error '-2147417848 (80010108)' Method 'Hidden' of
object 'Range' failed

I am using Excel 2000, but it the run-time error occured when I tested it in
Excel 2003, too. Any insight would be greatly appreciated.
 
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
Stop rows that i have hidden unhidding when i filter in excel APS Dave Excel Worksheet Functions 0 October 5th 07 11:06 AM
Excel 2003 - change columns to rows and rows to columns Trish Excel Discussion (Misc queries) 0 August 17th 07 02:22 AM
Excel 2003 - change columns to rows and rows to columns JLatham Excel Discussion (Misc queries) 0 August 17th 07 02:05 AM
Very slow unhidding rows Excel 2000 SP3 rs Excel Programming 4 May 19th 06 05:07 PM
Very slow unhidding rows Excel 2000 SP3 rs Excel Programming 0 May 19th 06 03:34 PM


All times are GMT +1. The time now is 08:03 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"