PDA

View Full Version : Solved: autofilter question



vzachin
05-21-2008, 06:29 AM
hi,

this is not a vba question.
i need to apply an autofilter in D4 and following columns if there is data in D5. in each subsequent column, if there is data, then there will be a header in the corresponding row. this works fine but if there is only one column D4 of data, when i apply the autofilter in D4, the autofilter is in D1. If i remove the entries in D13, then the autofilter will be applied in D4.
why is that? what am i doing wrong?


Sub AutoFiltOn2()
With ActiveSheet
.AutoFilterMode = False
If .Range("D5") <> "" Then
iCols = .Cells(4, .Columns.Count).End(xlToLeft).Column
.Range("D4", .Cells(4, iCols)).AutoFilter
End If
End With
End Sub
End Sub


thanks
zach

vzachin
05-21-2008, 06:30 AM
forgot to attach a file.sorry

DoLoop
05-21-2008, 06:46 AM
Change your code in:


Sub AutoFiltOn2()
With ActiveSheet
.AutoFilterMode = False
If .Range("D5") <> "" Then
.Range("D4", Range("D4").End(xlToRight)).AutoFilter
End If
End With
End Sub

vzachin
05-21-2008, 07:59 AM
Hi DoLoop,

thanks. didn't realize i was coding the hard way.

zach