I have a range of data with many columns, and each day it will be updated-- it will always have the same columns but a variable number of rows. The goal is that my macro will look at a specific set of 39 columns in the middle of the range beginning with the right most one, and examine the cells (not including a header name cell) in that column to see if they are null. If they are all null, the macro is supposed to hide the column and then move a column to the left and repeat. The macro should stop when it finds a column that has data in one of the cells. This is the code:
Sub HideEmptyColumns()
Application.ScreenUpdating = False
Dim lRow As Long
lRow = ActiveSheet.Cells(Rows.Count, "C").End(xlUp).Row
a_tab = ActiveSheet.Name
For x = 49 To 11 Step -1
anybody = False
For y = 8 To lRow
chk_yx = Worksheets(a_tab).Cells(y, x)
If Not IsNull(chk_yx) Then anybody = True
Next y
If Not anybody Then Worksheets(a_tab).Cells(1, x).ColumnWidth = 0
Next x
Application.ScreenUpdating = True
End Sub
This looks like it ought to work, but when I test it, it does not hide the columns that it should. Anybody see an error?
Sub HideEmptyColumns()
Application.ScreenUpdating = False
Dim lRow As Long
lRow = ActiveSheet.Cells(Rows.Count, "C").End(xlUp).Row
a_tab = ActiveSheet.Name
For x = 49 To 11 Step -1
anybody = False
For y = 8 To lRow
chk_yx = Worksheets(a_tab).Cells(y, x)
If Not IsNull(chk_yx) Then anybody = True
Next y
If Not anybody Then Worksheets(a_tab).Cells(1, x).ColumnWidth = 0
Next x
Application.ScreenUpdating = True
End Sub
This looks like it ought to work, but when I test it, it does not hide the columns that it should. Anybody see an error?