Another VBA question to hide/unhide rows based on cell value in another sheet

bertible

New Member
Joined
Mar 15, 2024
Messages
16
Office Version
  1. 2021
Platform
  1. Windows
I've reviewed many responses on this question, both on MrExcel and elsewhere, and just can't seem to get my hide-rows macro to run in Excel "LTSC":

I've tried a few syntax alternatives to the following "Case" method, but it just won't run (I did have it running in the module as a manual macro but not in the worksheet by a cell change). You will see two versions here, the second inactive one commented with leading '. (I've tried many different syntaxes). The range name TBOEx is a single cell j24 on sheet 2 (with a pulldown Yes,No validation). This is typical in my spreadsheet designs, to have a parameters page in which the user selects options, then a series of separate results pages. The rows I wish to hide when there is not data (Case "No") and to show in case "Yes", are on two other sheets, 12&13. i have a separate Case VBA Sub on this Sheet2 to hide and show complete worksheets and that one works fine from another pulldown cell. I've saved and reopened, rebooted, etc

VBA Code:
Private Sub HideRowsTBOEx(ByVal Target As Range)
'added below 2 lines per recommendation of several  forums
TBOX = Worksheets("Sheet2").Range("TBOEx").Value
If Intersect(TBOX, Target) Is Nothing Then Exit Sub

Select Case TBOX
        Case "No"
            Worksheets("Sheet12").Rows("36:48").Hidden = True
            Worksheets("Sheet3").Rows("36:48").Hidden = True
        Case "Yes"
            Worksheets("Sheet12").Rows("36:48").Hidden = False
            Worksheets("Sheet3").Rows("36:48").Hidden = False
   End Select
End Sub

'Inactive version
'Sub HideRows(ByVal Target As Range)
'macro did run using F5 in module but not here in sheet2 and not yet automatic on TBOEx change

'Select Case Sheet2.Range("j24").Value
        'Case "No"
            'Sheet12.Range("36:48").EntireRow.Hidden = True
            'Sheet3.Range("36:48").EntireRow.Hidden = True
        'Case "Yes"
            'Sheet12.Range("36:48").EntireRow.Hidden = False
            'Sheet3.Range("36:48").EntireRow.Hidden = False
   ' End Select
'End Sub
 
Last edited by a moderator:
1711047108278.png


(Oops, when I added the snipped pic above, it moved me to a new message. )
To continue: this error appears when the output sheets are protected. (Sheets 12 &3) I've tried a couple of protection options, such as such as "format Rows" and I've also tried unlocking rows 36:48 in both sheets 12 &3. As soon as I reprotect the sheets, the error reappears. Note that I do not have admin rights to my computer, so can't install any repair software, or delete the XLStart file that some sites suggest for this error.

Thanks
Gary
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Yikes, Feeling a bit foolish. When I saved and exited the file it seemed to work fine after reload. All good at the moment.
 
Upvote 0
Try the following. Immediately after the Application.EnableEvents line, type:

VBA Code:
Me.Unprotect Password:= "password"

and immediately before Exit Sub type:

VBA Code:
Me.Protect Password:= "password"

replacing "password" with your actual password.
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,102
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top