Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Help- It's only a tiny change

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
PG Oriel - 14 Sep 2007 10:30 GMT
Hi,

I have the code below which hides empty columns when I autofilter from
column D onwards. The autofilter data sits in column C. All I want is the
Column data to sit in column D and it hide columns from E onwards. What
little thing do I change? 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(1, "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
Joel - 14 Sep 2007 11:16 GMT
The for loop count has to start at 3 (Col C) instead of 4 (Col D).

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(1, "IV").End(xlToLeft).Column
Set rngA = Me.AutoFilter.Range
Set rngA = rngA.Offset(1, 0) _
  .Resize(rngA.Rows.Count - 1, 1)
For i = 3 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

> Hi,
>
[quoted text clipped - 20 lines]
> Application.ScreenUpdating = True
> End Sub
PG Oriel - 16 Sep 2007 09:00 GMT
Hi, shouldn't it be 5 it I want it to filter from column E onwards and not 3?

> The for loop count has to start at 3 (Col C) instead of 4 (Col D).
>
[quoted text clipped - 40 lines]
> > Application.ScreenUpdating = True
> > End Sub
Joel - 16 Sep 2007 11:10 GMT
Yes 5 would be correct after I read your original posting.

> Hi, shouldn't it be 5 it I want it to filter from column E onwards and not 3?
>
[quoted text clipped - 42 lines]
> > > Application.ScreenUpdating = True
> > > End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.