Selecting every sheet

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have 2 worksheets that both have tool tips in the form of data validation input messages. There is a button on each sheet to toggle them on or off. Both buttons link to this procedure.

VBA Code:
Sub ToggleTips()
Quoting.Unprotect Password:=ToUnlock
Dim st As Range, cell As Range
        For Each st In ActiveSheet.UsedRange
            If HasValidation(st) Then
                st.Validation.ShowInput = Not st.Validation.ShowInput
            End If
        Next st
Quoting.Protect Password:=ToUnlock
End Sub

What code do I put for this sub to allow me to have just one button but it to toggle the tips on every sheet?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try using
VBA Code:
Sub ToggleTips()
Dim st As Range, cell As Range, ws As Worksheet
    For Each ws In Worksheets
    If ws.Name = "SheetNAME" Or ws.Name = "SheetName" Then
        ws.Activate
        ws.Unprotect Password:=ToUnlock
        For Each st In ActiveSheet.UsedRange
            If HasValidation(st) Then
                st.Validation.ShowInput = Not st.Validation.ShowInput
            End If
        Next st
        ws.Protect Password:=ToUnlock
    Next ws
End Sub
 
Upvote 0
I get an error, Next without for and the next on 2nd last line is highlighted.
 
Upvote 0
Thanks for helping today Michael. I need to go now but I will look at this some more when I am next at work on Wednesday.
 
Upvote 0
I thought you could have debugged and If ...End If error
VBA Code:
Sub ToggleTips()
Dim st As Range, cell As Range, ws As Worksheet
    For Each ws In Worksheets
    If ws.Name = "SheetNAME" Or ws.Name = "SheetName" Then
        ws.Activate
        ws.Unprotect Password:=ToUnlock
        For Each st In ActiveSheet.UsedRange
            If HasValidation(st) Then
                st.Validation.ShowInput = Not st.Validation.ShowInput
            End If
        Next st
        ws.Protect Password:=ToUnlock
    End If
    Next ws
End Sub
 
Upvote 0
Thanks for that Michael, I was looking for the next lines to loop the for each loops andI completely forgot about ending the if statements.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,749
Members
448,989
Latest member
mariah3

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