1

I am trying to write a simple code that automatically unhides the next row if data is entered on the previous row. the idea being as someone puts more details to the spreadsheet it grows as needed with all the excess rows hidden at the start.

The range is from rows 2 to 56 but row 56.

Data is entered from columns D to M but i only want column D to be evaluated when unhiding the rows

Sub UnHideRows()
Dim i As Integer
    If Target.Address = Worksheet("Blah").Range("D3:D55") Then
        i = ActiveCell.Row
        Worksheet("Blah").Row(i+1).hidden = false
    End if
End Sub

Unfortunatly this does not work and i only want it to unhide the following row if data is entered into the current rows D cell. any help would be appreciated. it doesnt need to rehide the row if all data is removed either.

1 Answer 1

1
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count = 1 And _
   Target.Offset(1, 0).EntireRow.Hidden Then
        Target.Offset(1, 0).EntireRow.Hidden = False
        ' Target.Offset(1, 0).Activate '
End If
End Sub

i only want column D to be evaluated when unhiding the rows

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count = 1 And _
   Target.Column = 4 And _
   Target.Offset(1, 0).EntireRow.Hidden Then
        Target.Offset(1, 0).EntireRow.Hidden = False
        ' Target.Offset(1, 0).Activate '
End If
End Sub
5
  • But this will unhide Row n+1 if something is entered anywhere on Row n, and the question asks that you look only at cell Dn. Commented Jan 17, 2020 at 7:12
  • @Scott Oops... Thank you. Updated.
    – Akina
    Commented Jan 17, 2020 at 7:24
  • Hi Akina, I added the code but it does not appear to do anything. do i need to enable to code or anything? also it is possible to only apply to code to a certain sheet and rows 2 - 55? Thank you. Commented Jan 20, 2020 at 1:14
  • @matthewwilcox I added the code but it does not appear to do anything. Where you add this code into? It must be a worksheet module. also it is possible to only apply to code to a certain sheet Put this code into a module for each worksheet. Or convert it into common public procedure and call it from each worksheet's module. and rows 2 - 55? Add according condition checking by Target.Row (or replace with Intersect).
    – Akina
    Commented Jan 20, 2020 at 4:42
  • Thanks so much. Got it to work. Commented Jan 20, 2020 at 4:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .