Hi louvaek
Here's your File with the Code embedded...
Hi louvaek
Here's your File with the Code embedded...
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please mark your Thread as SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Thanks Jaslake.
But something doesn't work. If I add a value, a row unhides indeed. But if I delete it again, it doesn't hide again
What's the diff. between your solution and Olly's? Which one should I use if I really have lot's of names in that list, and lot's of names that should be added by users?
Grtz
Kristof
Hi Kristof
The downside of Olly's Code is that the range of Cells is fixed. If that works for you then use it.I'll look at this![]()
If Not Intersect(Target, Range("B12:B17")) Is Nothing Then
But if I delete it again, it doesn't hide again
Well Olly's works, but I just tested something and the code missed it effect afterwards. I deleted a row (a name that should not longer be in the list) in the B3:B11 range.
After that, the code doesn't work anymore in B12 (B13 : B17 still works). If I delete another row, B13 doesn't work anymore.
So Olly's code is clean and simple, but should be manually changed each time I delete a row in the sheet.
I guess the code should have something with 'row()' included? I know a lot about formula's, but I am a real VBA newbie :-)
Hi Kristof
There's a bit of mind numbing logic going on here, see if this works as required![]()
Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) Dim OldValue As String, NewValue As String If Target.Cells.Count > 1 Then Exit Sub If Not Target.Column = 2 Then Exit Sub On Error GoTo Reset With Application .ScreenUpdating = False .EnableEvents = False .Undo OldValue = Target.Value 'store old value If Not OldValue = "" Then .Undo If Range(Target.Address).Offset(1, 0).Value = "" _ Or Range(Target.Address).Offset(-1, 0).Value = "" Then Range(Target.Address).EntireRow.Hidden = True End If .ScreenUpdating = True .EnableEvents = True Exit Sub Else .Undo NewValue = Target.Value 'store new value Range(Target.Address).Offset(1, 0).EntireRow.Hidden = False .EnableEvents = True .ScreenUpdating = True End If End With Reset: Application.ScreenUpdating = True Application.EnableEvents = True End Sub
Jaslake,
The unhiding works perfect. If I add a value in B13, B14 shows. If I add a value in B15, B15 shows.
But when I delete B14, B15 does not unhide, it's B14 that hides ... and B15 stays visible.
Hi Kristof
When you say "delete", are you deleting a Row or are you clearing the contents of the Cell?
If I delete the value (or values) in the B12:B17 range.
Deleting rows works fine with your VBA code.
Hi Kristof
If I understand the issue![]()
Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) Dim OldValue As String, NewValue As String If Target.Cells.Count > 1 Then Exit Sub If Not Target.Column = 2 Then Exit Sub On Error GoTo Reset With Application .ScreenUpdating = False .EnableEvents = False NewValue = Target.Value 'store new value .Undo OldValue = Target.Value 'store old value If Not OldValue = "" Then .Undo If NewValue = "" And Range(Target.Address).Offset(1, 0).Value = "" Then Range(Target.Address).Offset(1, 0).EntireRow.Hidden = True GoTo Reset End If If Range(Target.Address).Offset(1, 0).Value = "" _ And Range(Target.Address).Offset(-1, 0).Value = "" Then Range(Target.Address).EntireRow.Hidden = True GoTo Reset End If Else .Undo Range(Target.Address).Offset(1, 0).EntireRow.Hidden = False End If End With Reset: Application.ScreenUpdating = True Application.EnableEvents = True End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks