Hi guys,
I'm just starting with VBA and I'm running into a situation that I'm not understanding...
I am trying to write a module for a sheet that will hide rows (between 1 and 42) when cell Ax is blank. Here is the code that I have so far but it is only hiding one row (the first row where Ax is blank).
************************************************
Sub HideBlankRows()
' select all the rows
Application.ScreenUpdating = False
Dim myLastRow As Long
Range("A1").Select
On Error Resume Next
myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
myRange = "a1:" & "a42"
Application.ScreenUpdating = True
Range(myRange).Select
' hide empty rows
Rng = Selection.Rows.Count
ActiveCell.RowOffset(0, 0).Select
Application.ScreenUpdating = False
For i = 1 To Rng
If ActiveCell.Value = "" Then
Selection.EntireRow.Hidden = True
Else
ActiveCell.Offset(1, 0).Select
End If
Next i
Application.ScreenUpdating = True
End Sub
**************************************************
Any ideas?
I'm just starting with VBA and I'm running into a situation that I'm not understanding...
I am trying to write a module for a sheet that will hide rows (between 1 and 42) when cell Ax is blank. Here is the code that I have so far but it is only hiding one row (the first row where Ax is blank).
************************************************
Sub HideBlankRows()
' select all the rows
Application.ScreenUpdating = False
Dim myLastRow As Long
Range("A1").Select
On Error Resume Next
myLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
myRange = "a1:" & "a42"
Application.ScreenUpdating = True
Range(myRange).Select
' hide empty rows
Rng = Selection.Rows.Count
ActiveCell.RowOffset(0, 0).Select
Application.ScreenUpdating = False
For i = 1 To Rng
If ActiveCell.Value = "" Then
Selection.EntireRow.Hidden = True
Else
ActiveCell.Offset(1, 0).Select
End If
Next i
Application.ScreenUpdating = True
End Sub
**************************************************
Any ideas?