Thread: hide columns
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default hide columns

Hi Minostrada,

Does anybody know what the best code is?



With a pre-emptive "Best" disclaimer, try:

'=============
Sub Tester01()
Dim rng As Range, rng2 As Range, rng3 As Range
Dim col as Range

Application.ScreenUpdating = False

On Error Resume Next
Set rng = ActiveSheet.AutoFilter.Range

rng.EntireColumn.Hidden = False
If Not rng Is Nothing Then
Set rng2 = rng.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
For Each col In rng2.Columns
Set rng3 = Intersect(col.EntireColumn, rng2)
col.EntireColumn.Hidden = Application.CountA(rng3) < 2
Next col
End If

Application.ScreenUpdating = True

End Sub
'<<=============


---
Regards,
Norman


"minostrada" wrote in message
...
hi,

I'm building a database in Excel. At the moment I use a autofilter. But
the
database got so many possibilities that I'm trying to write a VB code to
hide
the empty columns out of the filtered results.

Does anybody know what the best code is?

thanks for so far!