Hi all, I am trying to write a simple code on my worksheet that when I activate the worksheet it checks for blank cells and if they are empty it hides the columns. This is to neaten up my sheet. I want to keep columns A thru H and columns after L. My code looks like this.
Private Sub Worksheet_Activate()
Dim I as Integer
I = 9
Application.ScreenUpdating = False
Columns("I:L".select
Selection.EntireColumn.hidden = True 'This line should set I:L hidden in the worksheet.
Do Until IsEmpty(Cells(4, I)) or I = 13 'Checking for empty Non Empty cells untill finds one. Starting cell should be I4 or Cells(4, I) I=9 to start.
Cells(4, I).EntireColumn.hidden = False
I = I + 1
Loop
End Sub
My problem when I run this is it makes all columns from A through L Hidden. I think it is do to the Cells(4, i) line. It should be refering to cell I4 fourth Row Column 9 Yet When I walk through it it seems to be pointing to different cell almost like Column 3 row 9 or 10 Not sure. Any help would be great.
Eric
Private Sub Worksheet_Activate()
Dim I as Integer
I = 9
Application.ScreenUpdating = False
Columns("I:L".select
Selection.EntireColumn.hidden = True 'This line should set I:L hidden in the worksheet.
Do Until IsEmpty(Cells(4, I)) or I = 13 'Checking for empty Non Empty cells untill finds one. Starting cell should be I4 or Cells(4, I) I=9 to start.
Cells(4, I).EntireColumn.hidden = False
I = I + 1
Loop
End Sub
My problem when I run this is it makes all columns from A through L Hidden. I think it is do to the Cells(4, i) line. It should be refering to cell I4 fourth Row Column 9 Yet When I walk through it it seems to be pointing to different cell almost like Column 3 row 9 or 10 Not sure. Any help would be great.
Eric