I am working with data that's imported from a NOSQL database.
Sometimes I get worksheets with 1000 columns and up where most of the cells have no data in them.
I am looking for a way that when I filter the data and show only specific rows, all the columns for the visible rows which have no data at all will hide automatically.
This way, I will not have to horizontally scroll hundreds of empty columns looking for information.
If you have a solution for this need, I will be grateful.
Thanks,
Hanan Cohen
Answer
This code will hide columns if only the header cell is filled:
Sub KolumnHider()
Dim wf As WorksheetFunction
Dim i As Long, r As Range
Set wf = Application.WorksheetFunction
For i = 1 To 1000
Set r = Cells(1, i).EntireColumn
If wf.CountA(r) < 2 Then r.Hidden = True
Next i
End Sub
If there are no column headers, then make the 2 into a 1.
No comments:
Post a Comment