I have tried multiple variations of trying to shorten the script for these 3 events (as they are all closely related) mainly trying to utilize a couple of "ElseIf" statements....
my current code:
What the code is doing:
1. code is executed via a userform where the user can choose 1 of 3 options:
2. the code looks at rows that are currently VISIBLE in column "AB"/28 when the code is ran.
3. if the row contains the string that corresponds to each checkbox, then it allows that row to remain UNHIDDEN and hides all other rows that dont match.
4. it does this for each of the 3 options available: (1. "seatex fault" = "SF", 2. "not seatex fault" = "NF" and 3. "unknown fault" = "UF" )
So my question is, is there a way to shorten/combine these 3 statements into 1 statement such as using a "ElseIf" method?
my current code:
VBA Code:
'*************************************************************************************************************************************************************************
' CHECKBOXES FOR SHOWING WHO'S FAULT THE INCIDENT IS (SEATEX, NOT SEATEX OR NOT KNOWN):
' SHOW ONLY INCIDENTS THAT ARE *SEATEX'* FAULT:
Dim rSEA As Long
rSEA = Worksheets("REPORTS").Range(Cells(30, 5), Cells(rRow, 5)).SpecialCells(xlCellTypeVisible).Cells.Count
If rSEA <= 1 Then
'
Else
If chkOurFault.value = True Then
For Each Cell In ActiveWorkbook.Worksheets("REPORTS").Range(Cells(31, 28), Cells(rRow, 28)).SpecialCells(xlCellTypeVisible)
If Cell.value = "SF" And Rows(Cell.Row).Hidden = False Then ' IF THE INCIDENT IS *SEATEX FAULT* THEN KEEP THAT ROW UNHIDDEN:
Rows(Cell.Row).Hidden = False
Else
Rows(Cell.Row).Hidden = True ' ELSE NO CURRENTLY UNHIDDEN RECORDS MATCH THE CHKBOX SELECTION, SO HIDE ALL OF THOSE ROWS
End If
Next
End If
End If
'**********************************************************************
' SHOW ONLY INCIDENTS THAT ARE NOT *SEATEX'* FAULT:
If rSEA <= 1 Then
'
Else
If chkNotOurFault.value = True Then
For Each Cell In ActiveWorkbook.Worksheets("REPORTS").Range(Cells(31, 28), Cells(rRow, 28)).SpecialCells(xlCellTypeVisible)
If Cell.value = "NF" And Rows(Cell.Row).Hidden = False Then ' IF THE INCIDENT IS *NOT* SEATEX FAULT THEN KEEP THAT ROW UNHIDDEN:
Rows(Cell.Row).Hidden = False
Else
Rows(Cell.Row).Hidden = True ' ELSE NO CURRENTLY UNHIDDEN RECORDS MATCH THE CHKBOX SELECTION, SO HIDE ALL OF THOSE ROWS
End If
Next
End If
End If
'**********************************************************************
' SHOW ONLY INCIDENTS WHERE THE FAULT IS UNKNOWN:
If rSEA <= 1 Then
'
Else
If chkUnknownFault.value = True Then
For Each Cell In ActiveWorkbook.Worksheets("REPORTS").Range(Cells(31, 28), Cells(rRow, 28)).SpecialCells(xlCellTypeVisible)
If Cell.value = "UF" And Rows(Cell.Row).Hidden = False Then ' IF THE INCIDENT IS *UNKNOWN FAULT* THEN THEN KEEP THAT ROW UNHIDDEN:
Rows(Cell.Row).Hidden = False
Else
Rows(Cell.Row).Hidden = True ' ELSE NO CURRENTLY UNHIDDEN RECORDS MATCH THE CHKBOX SELECTION, SO HIDE ALL OF THOSE ROWS
End If
Next
End If
End If
'
What the code is doing:
1. code is executed via a userform where the user can choose 1 of 3 options:
2. the code looks at rows that are currently VISIBLE in column "AB"/28 when the code is ran.
3. if the row contains the string that corresponds to each checkbox, then it allows that row to remain UNHIDDEN and hides all other rows that dont match.
4. it does this for each of the 3 options available: (1. "seatex fault" = "SF", 2. "not seatex fault" = "NF" and 3. "unknown fault" = "UF" )
So my question is, is there a way to shorten/combine these 3 statements into 1 statement such as using a "ElseIf" method?