VBA - If....Then not working in a For......Next Loop (Sorry, I'm a newbie!)
Hi all. I have a very simple task to carry out that I'm sure a child could sort for me.
(i) I want to go to a cell address & check whether it's empty or not.
(ii) If it's empty I wish to ignore it & check the cell below - If it's not, I wish to hide the entire line that the cells is located on.
(iii) I then wish to check the next 49 lines below and carry on with the macro.
The code I have written is as follows:
Range("g1").Select
For i = 1 To 50
If ActiveCell.Value <> 0 Then
ActiveCell.Rows("1:1").EntireRow.Select
Selection.EntireRow.Hidden = True
ElseIf ActiveCell.Value = 0 Then
ActiveCell.Offset(1, 0).Select
Next
End If
I might try something like this.
For i = 1 To 50
Worksheets("Sheet1").Cells(i, 7).Select
If ActiveCell.Value <> "" Then
Worksheets("Sheet1").Rows(i).EntireRow.Select
Selection.EntireRow.Hidden = True
End If
Next