PC Review


Reply
Thread Tools Rate Thread

Adapt hiding columns?

 
 
=?Utf-8?B?UEcgT3JpZWw=?=
Guest
Posts: n/a
 
      15th Nov 2006
I have the following code which hides blank columns in my autofilter, but
this was set up to work for rows 3 downawards. I'd like to adapt it to work
in another sheet, starting at row 2. Any ideas? Thanks.

Sub ABC()
Dim lastColumn As Long, rngA As Range, i As Long
Dim rng1 As Range
Application.ScreenUpdating = False
Columns.Hidden = False
lastColumn = Me.Cells(2, "IV").End(xlToLeft).Column
Set rngA = Me.AutoFilter.Range
Set rngA = rngA.Offset(1, 0) _
.Resize(rngA.Rows.Count - 1, 1)
For i = 4 To lastColumn
Set rng1 = Cells(3, i).Resize(rngA.Rows.Count, 1)
If Application.Subtotal(3, rng1) = 0 Then
Columns(i).Hidden = True
End If
Next
Application.ScreenUpdating = True
End Sub
 
Reply With Quote
 
 
 
 
wisccal@googlemail.com
Guest
Posts: n/a
 
      15th Nov 2006
If I understand you correctly, then all you need to do is change 3 to 2
in the following row:

Set rng1 = Cells(2, i).Resize(rngA.Rows.Count, 1) ''set range to start
from row 2 instead of 3

But I'm not sure if this really is all that you are after.

Regards,
Steve

PG Oriel wrote:

> I have the following code which hides blank columns in my autofilter, but
> this was set up to work for rows 3 downawards. I'd like to adapt it to work
> in another sheet, starting at row 2. Any ideas? Thanks.
>
> Sub ABC()
> Dim lastColumn As Long, rngA As Range, i As Long
> Dim rng1 As Range
> Application.ScreenUpdating = False
> Columns.Hidden = False
> lastColumn = Me.Cells(2, "IV").End(xlToLeft).Column
> Set rngA = Me.AutoFilter.Range
> Set rngA = rngA.Offset(1, 0) _
> .Resize(rngA.Rows.Count - 1, 1)
> For i = 4 To lastColumn
> Set rng1 = Cells(3, i).Resize(rngA.Rows.Count, 1)
> If Application.Subtotal(3, rng1) = 0 Then
> Columns(i).Hidden = True
> End If
> Next
> Application.ScreenUpdating = True
> End Sub


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hiding Columns =?Utf-8?B?RGF2aWQgQS4=?= Microsoft Excel Programming 2 14th Sep 2007 09:56 PM
Hiding column/row labels --without hiding entire columns/rows daniel.wolff@csfb.com Microsoft Excel Discussion 2 19th Oct 2005 02:28 AM
Hiding Columns belony Microsoft Excel Misc 4 15th Jun 2005 12:27 AM
Hiding columns Randy Microsoft Excel Misc 0 11th Dec 2003 07:24 PM
Hiding Macro Buttons when right-clicking>Hiding Columns Brooks Microsoft Excel Misc 1 16th Jul 2003 07:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:15 PM.