Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Problem with Hiding Every Other Column

I have two workbooks/files - both workbooks have the macro below that
hides every column starting with Column B.

Sub hidecol()

Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For i = 2 To 255 Step 2
If Columns(i).Hidden = False Then
Columns(i).Hidden = True
Else
Columns(i).Hidden = False
End If
Next i
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub


In workbook 1 it works just fine but in Workbook 2, it stops at the
following line: Columns(i).Hidden = True

The only difference (that I can detect) between the 2 workbooks is in
Workbook 2 there are more columns that contain data than in workbook
1.

Any ideas??

Thx!



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Problem with Hiding Every Other Column

i'd use something like this, unless i don't understand what you're tying to
accomplish:

Sub hidecol()
Dim ws As Worksheet
Dim i As Long
Set ws = Worksheets("Sheet1")
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
ws.Columns("A:IV").Hidden = False
For i = 2 To 255 Step 2
ws.Columns(i).Hidden = True
Next i
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub

--


Gary

"samdev" wrote in message
...
I have two workbooks/files - both workbooks have the macro below that
hides every column starting with Column B.

Sub hidecol()

Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For i = 2 To 255 Step 2
If Columns(i).Hidden = False Then
Columns(i).Hidden = True
Else
Columns(i).Hidden = False
End If
Next i
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub


In workbook 1 it works just fine but in Workbook 2, it stops at the
following line: Columns(i).Hidden = True

The only difference (that I can detect) between the 2 workbooks is in
Workbook 2 there are more columns that contain data than in workbook
1.

Any ideas??

Thx!





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Problem with Hiding Every Other Column

Hi
Comments and other objects on the screen can stop columns hiding. If
you have such, right click them, go to format and in properties choose
"move and size with cells".
regards
Paul

On Oct 14, 6:43*am, samdev wrote:
I have two workbooks/files - both workbooks have the macro below that
hides every column starting with Column B.

Sub hidecol()

Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For i = 2 To 255 Step 2
If Columns(i).Hidden = False Then
Columns(i).Hidden = True
Else
Columns(i).Hidden = False
End If
Next i
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub

In workbook 1 it works just fine but in Workbook 2, it stops at the
following line: Columns(i).Hidden = True

The only difference (that I can detect) between the 2 workbooks is in
Workbook 2 there are more columns that contain data than in workbook
1.

Any ideas??

Thx!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Problem with Hiding Every Other Column

On Oct 14, 2:03*am, "Gary Keramidas" <GKeramidasAtMsn.com wrote:
i'd use something like this, unless i don't understand what you're tying to
accomplish:

Sub hidecol()
* * * Dim ws As Worksheet
* * * Dim i As Long
* * * Set ws = Worksheets("Sheet1")
* * * Application.Calculation = xlCalculationManual
* * * Application.ScreenUpdating = False
* * * ws.Columns("A:IV").Hidden = False
* * * For i = 2 To 255 Step 2
* * * * * * ws.Columns(i).Hidden = True
* * * Next i
* * * Application.ScreenUpdating = True
* * * Application.Calculation = xlCalculationAutomatic
End Sub

--

Gary

"samdev" wrote in message

...



I have two workbooks/files - both workbooks have the macro below that
hides every column starting with Column B.


Sub hidecol()


Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For i = 2 To 255 Step 2
If Columns(i).Hidden = False Then
Columns(i).Hidden = True
Else
Columns(i).Hidden = False
End If
Next i
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub


In workbook 1 it works just fine but in Workbook 2, it stops at the
following line: Columns(i).Hidden = True


The only difference (that I can detect) between the 2 workbooks is in
Workbook 2 there are more columns that contain data than in workbook
1.


Any ideas??


Thx!- Hide quoted text -


- Show quoted text -


I tried this and it still stops at the ws.Columns(i).Hidden = True -
the error msg is "unable to set the Hidden Property of the range
class".

I checked and the "move and size with cells" options are turned on for
the objects (they are buttons).

What is puzzling is why it works in one file but not the other - the
file that it is not working just has more columns with data, other
than that they are the same.....

Any other ideas.....thx,
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
Hiding a column of hyperlinks behind a column of numbers cmiling New Users to Excel 2 November 20th 09 05:02 PM
Problem in hiding columns Hardik Shah Excel Discussion (Misc queries) 2 August 29th 08 12:54 AM
Hiding column if cell in previous column is empty-revised [email protected] Excel Programming 2 January 4th 07 06:45 AM
Hiding Column Also hiding text Cindy Excel Programming 0 April 6th 06 07:18 PM
Need help hiding/unhiding column based on autofilter selection in a different column kcleere Excel Programming 1 January 23rd 06 06:21 AM


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