View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
PG Oriel PG Oriel is offline
external usenet poster
 
Posts: 37
Default Help- It's only a tiny change

Hi, shouldn't it be 5 it I want it to filter from column E onwards and not 3?

"Joel" wrote:

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


"PG Oriel" wrote:

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