Hide columns without data

  • Thread starter Thread starter johan
  • Start date Start date
J

johan

Hello,

Somebody can help me ?

I need a macro that hide all the columns from column C till the last
used column where no data is registrated in recordnr 2.
Remarks..... in record nr.2, in all the columns, a formula is
registrated just looks like
=if(A1="";"";A1).
So, there's no real visible data in some records (only the formula as
mentioned)

regards and thanks,
Johan
 
Paste into a standard module - and make changes (***) to suit.

Sub PrintOnlyColumnsWithValues()
Dim cell As Range
Application.ScreenUpdating = False
With ActiveSheet
For Each cell In .Range("C20:K20") '<<<<***
If cell.Value = 0 Then cell.EntireColumn.Hidden = True
Next
.PrintOut ' Or PrintPreview
.Range("C20:K20").Columns.Hidden = False '<<<<***
End With
Application.ScreenUpdating = True
End Sub

Also, in your Thisworkbook module, paste in:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Application.EnableEvents = False
PrintOnlyColumnsWithValues
Cancel = True
Application.EnableEvents = True
End Sub

HTH

Jim May
 
Back
Top