Apr 10 2024 12:12 PM
Hi All, hoping for some help. Our business has high and low employment demand depending on the number and size of projects, as a result we terminate and rehire many of the same employees over time. Additionally, we offer 3 different types of PTO tracked in 3 separate workbooks, so adding, removing and re-adding the same employees gets time consuming. I would like to hide a row based on a date being entered in the termination date column D and unhide the row when the employee is rehired. If possible, to unhide terminated employee enter their name in C1; to temporarily unhide row then clear the termination date and enter the rehire date in Column E to keep row unhidden; if they are terminated/rehired at a later date the same action repeats, except then the rehire date would, be cleared the next time the same employee is terminated. I would, also, note that the row range will grow over time.
I have tried Advanced Filters, but this action to hide then unhide rows is not efficient and leaves room for too many errors where multiple users are involved.
I'm not well versed in VBA, but see that it is, likely, my only option; it will be the only VBA in the workbook. If what I'm asking is not a viable option, what would be the best solution? Any help is greatly appreciated.
Thank you,
Shawn
Apr 10 2024 10:54 PM
Creating a VBA solution for your scenario is indeed a viable option and can automate the process effectively. Here is a basic outline of how you can implement this:
Here is a sample VBA code to get you started:
Vba code is untested, please backup your file.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
Dim lastRow As Long
'Get the last row in column D
lastRow = Cells(Rows.Count, "D").End(xlUp).Row
'Loop through each cell in column D
For Each cell In Range("D2:D" & lastRow)
'Check if the cell contains a termination date
If IsDate(cell.Value) Then
'Hide the row if a termination date is entered
cell.EntireRow.Hidden = True
Else
'Unhide the row if no termination date is entered
cell.EntireRow.Hidden = False
End If
Next cell
End Sub
This code will hide the entire row if a termination date is entered in column D, and it will unhide the row if the termination date is cleared. You will need to place this code in the code module for the worksheet where you want this functionality.
This should provide a basic framework for automating the hiding and unhiding of rows based on termination and rehire dates in Excel using VBA. You can further enhance the code based on your specific needs and workflow. The text, steps and code was created with the help of AI.
Simply implementing your requirement with formulas can be challenging due to the dynamic nature of showing and hiding rows based on changing data.
However, you can achieve some level of automation using helper columns and conditional formatting, although this may not fully reproduce the functionality of VBA.
Hope this will help you.
Was the answer useful? Mark as best response and like it!
This will help all forum participants.
Apr 11 2024 06:19 AM