trying to get a commandbutton working where it toggles between hiding columns that a cell in each either contains an "R" or and "E". When the user clicks on the button it hides those columns and changes the caption to indicate what is currently being viewed.
THIS simple code works that I use in a different workbook:
The new code that I have been trying to make work takes that code a step further where instead of hiding specific columns/rows, the new one will look to see if the column contains a certain character ("R" or an "E") and hides only those rows... here is the code that i have (NOT working)
Ultimately I need to make this (somehow) a 3-way switch (hence why I am trying to get it to work with ElseIf) because I also need it to toggle not only columns with "R" or "E", but also ones with "R" and "E" (but not in the same cell... separate cells that contain either "R" or "E")
I was hoping to get it working with 2 options first before exanding it to include the 3 different options.
Thanks for any assistance anyone can throw my way.
THIS simple code works that I use in a different workbook:
Code:
Private Sub cmdShowHide_Click()
If cmdShowHide.Caption = "Hide Hidden Columns" Then
ActiveWorkbook.Worksheets("Seatex Incident Log").Range("C1,E1,O1").EntireColumn.Hidden = True
cmdShowHide.Caption = "Show Columns"
Else
ActiveWorkbook.Worksheets("Seatex Incident Log").Range("C1,E1,O1").EntireColumn.Hidden = False
cmdShowHide.Caption = "Hide Hidden Columns"
End If
End Sub
The new code that I have been trying to make work takes that code a step further where instead of hiding specific columns/rows, the new one will look to see if the column contains a certain character ("R" or an "E") and hides only those rows... here is the code that i have (NOT working)
Code:
Private Sub CommandButton30_Click()
' button for EL CAMPO EMPLOYEES(NEW)
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
ActiveWindow.ScrollColumn = 1
Dim lCol As Long
lCol = ActiveSheet.UsedRange.Columns.Count
rCol = ActiveSheet.UsedRange.Rows.Count
If CommandButton30.Caption = "EL-CAMPO" Then
For Each Cell In Range(Cells(5, 6), Cells(5, lCol)).SpecialCells(xlCellTypeVisible)
If Cell = "E" Then Columns(Cell.Column).Hidden = False Else Columns(Cell.Column).Hidden = True
Next
CommandButton30.Caption = "ROSENBERG"
ElseIf CommandButton30.Caption = "ROSENBERG" Then
For Each Cell In Range(Cells(5, 6), Cells(5, lCol)).SpecialCells(xlCellTypeVisible)
If Cell = "R" Then Columns(Cell.Column).Hidden = False Else Columns(Cell.Column).Hidden = True
End If
End Sub
Ultimately I need to make this (somehow) a 3-way switch (hence why I am trying to get it to work with ElseIf) because I also need it to toggle not only columns with "R" or "E", but also ones with "R" and "E" (but not in the same cell... separate cells that contain either "R" or "E")
I was hoping to get it working with 2 options first before exanding it to include the 3 different options.
Thanks for any assistance anyone can throw my way.