dropkickweasel
Board Regular
- Joined
- Feb 2, 2014
- Messages
- 70
I have a workbook that lists products.
One of the columns has a drop-down box to determine if each product is 'fresh' or 'destroyed'.
If a product is marked as 'destroyed', then the row of that product is hidden on the sheet.
This is the macro that automatically hides the row when the product selection is set to 'destroyed'.
In the event that I accidentally set a product to 'destroyed', I would like a button on the worksheet that I can click to unhide the most recently hidden row.
This won't necessarily be the final row in the worksheet.
If I catch it immediately, it will be the row that was most recently modified by changing 'fresh' to 'destroyed'.
Here's the code I'm using at the moment:
Column H is the column with 'destroyed' in it.
It's not working as I want it to.
I believe it is unhiding the last hidden row (as in, the row that appears last on the worksheet), not the last hidden row (as in the row that was hidden most recently, regardless of where it appears on the worksheet).
I am not a confident VBA user and have frankensteined the code together from research and kind strangers.
Does anyone have a way to adapt the code to unhide the most recently hidden row, not the lowest hidden row on the worksheet?
Many thanks.
One of the columns has a drop-down box to determine if each product is 'fresh' or 'destroyed'.
If a product is marked as 'destroyed', then the row of that product is hidden on the sheet.
This is the macro that automatically hides the row when the product selection is set to 'destroyed'.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
' Exit code if multiple cells updated at once
If Target.CountLarge > 1 Then Exit Sub
' See if column H was updated to "Destroyed"
If Target.Column = 8 And Target = "Destroyed" Then
Rows(Target.Row).Hidden = True
End If
End Sub
In the event that I accidentally set a product to 'destroyed', I would like a button on the worksheet that I can click to unhide the most recently hidden row.
This won't necessarily be the final row in the worksheet.
If I catch it immediately, it will be the row that was most recently modified by changing 'fresh' to 'destroyed'.
Here's the code I'm using at the moment:
Code:
Sub UnhideLastHiddenRow()
Dim lRow As Long
With Range("H:H").SpecialCells(xlCellTypeVisible)
lRow = .Areas.Count
.Areas(lRow).Cells(1, 1).Offset(-1, 0).EntireRow.Hidden = False
End With
End Sub
Column H is the column with 'destroyed' in it.
It's not working as I want it to.
I believe it is unhiding the last hidden row (as in, the row that appears last on the worksheet), not the last hidden row (as in the row that was hidden most recently, regardless of where it appears on the worksheet).
I am not a confident VBA user and have frankensteined the code together from research and kind strangers.
Does anyone have a way to adapt the code to unhide the most recently hidden row, not the lowest hidden row on the worksheet?
Many thanks.