Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default macro doesn't hide columns for an unexplicable reason

Thank you Bernie for the hidecolumn macro. It is easier to read, there is
still a problem however, it doesn't hide any columns.

I know this macro should work but it doesn't. I checked the worksheet
properties, read-only or hidden is not checked. I checked options and there
is nothing under security. I even unfiltered the columns thinking it
wouldn't hide the filtered ones. Why isn't it hiding the columns with n/a.
Could it be it doesn't like the slash and I have to escape it when it
searches for the string n/a ?

Public Sub FORMAT_VOD_HideColumns()
Dim C As Range
Application.ScreenUpdating = False

For Each C In Intersect(Range("12:64000"), ActiveSheet.UsedRange).Columns
If Application.CountIf(C.Cells, "N/A") = C.Cells.Count Then
C.EntireColumn.Hidden = True
Else
C.EntireColumn.Hidden = False

End If
Next C

Application.ScreenUpdating = True

End Sub

What am I missing?

tia,

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default macro doesn't hide columns for an unexplicable reason

Have you tried setting a break point where you think the If statement should
be true to see if it is, in fact, true? Of have you tried stepping through
to see if it is executing the statements as expected?

If it is not hiding the columns, then the first thing to check is if the
criteria is being returned in the If statement.
"Janis" wrote:

Thank you Bernie for the hidecolumn macro. It is easier to read, there is
still a problem however, it doesn't hide any columns.

I know this macro should work but it doesn't. I checked the worksheet
properties, read-only or hidden is not checked. I checked options and there
is nothing under security. I even unfiltered the columns thinking it
wouldn't hide the filtered ones. Why isn't it hiding the columns with n/a.
Could it be it doesn't like the slash and I have to escape it when it
searches for the string n/a ?

Public Sub FORMAT_VOD_HideColumns()
Dim C As Range
Application.ScreenUpdating = False

For Each C In Intersect(Range("12:64000"), ActiveSheet.UsedRange).Columns
If Application.CountIf(C.Cells, "N/A") = C.Cells.Count Then
C.EntireColumn.Hidden = True
Else
C.EntireColumn.Hidden = False

End If
Next C

Application.ScreenUpdating = True

End Sub

What am I missing?

tia,

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default macro doesn't hide columns for an unexplicable reason

I posted this before but never saw it on the reader, so here it is again.

The problem was in your Range("12:64000"). It left a lot of blank cells
beneath your used range. So I set the last row at the bottom of column D in
the UsedRange and it worked. You might want to use a different column to set
the last row, but now you know where the problem lies. Here is the modified
code.

Public Sub FORMAT_VOD_HideColumns() 'Hides a column if all cells in
range = specific value.
Dim C As Range
lr = ActiveSheet.Cells(Rows.Count, 4).End(xlUp).Row
Application.ScreenUpdating = False
For Each C In Intersect(Range("12:" & lr), ActiveSheet.UsedRange).Columns
If Application.CountIf(C.Cells, "N/A") = C.Cells.Count Then
C.EntireColumn.Hidden = True
Else
C.EntireColumn.Hidden = False
MsgBox C.Address
End If
Next C
Application.ScreenUpdating = True
End Sub


"Janis" wrote:

Thank you Bernie for the hidecolumn macro. It is easier to read, there is
still a problem however, it doesn't hide any columns.

I know this macro should work but it doesn't. I checked the worksheet
properties, read-only or hidden is not checked. I checked options and there
is nothing under security. I even unfiltered the columns thinking it
wouldn't hide the filtered ones. Why isn't it hiding the columns with n/a.
Could it be it doesn't like the slash and I have to escape it when it
searches for the string n/a ?

Public Sub FORMAT_VOD_HideColumns()
Dim C As Range
Application.ScreenUpdating = False

For Each C In Intersect(Range("12:64000"), ActiveSheet.UsedRange).Columns
If Application.CountIf(C.Cells, "N/A") = C.Cells.Count Then
C.EntireColumn.Hidden = True
Else
C.EntireColumn.Hidden = False

End If
Next C

Application.ScreenUpdating = True

End Sub

What am I missing?

tia,

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
Using a macro to hide columns Plum Excel Programming 9 April 26th 07 10:16 PM
Need a macro to hide certain columns Dallman Ross Excel Discussion (Misc queries) 12 October 19th 06 05:58 PM
I set up a macro to hide/unhide columns. It hides more columns Lori Excel Programming 1 September 6th 06 04:08 PM
hide columns macro xkarenxxxx Excel Programming 5 June 2nd 06 05:27 PM
macro to hide columns Shooter Excel Worksheet Functions 2 September 27th 05 09:04 PM


All times are GMT +1. The time now is 05:35 PM.

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

About Us

"It's about Microsoft Excel"