Protecting all Sheets then selecting a specific Sheet

MikeRetyred

New Member
Joined
May 18, 2019
Messages
11
My project is to recreate MS Money in Excel - thanks to my son’s advice and the inspiration from the helpful members of various Excel Forums. Now it’s testing, creating and revising display formats and testing, testing again.
Could any member help me to find a solution and to understand why this lates glitch happens?
To protect all worksheets I use this macro which works every time:
Sub ProtectAllWorksheets()
'Protects all Worksheets in Workbook
'Loop through all worksheets
Dim ws As Worksheet
For Each ws In Worksheets
ws.Protect
Next ws
End Sub
After protection I’d like to go to a specific sheet and tried this addition to the macro:
Sub ProtectAllWorksheets()
'Protects all Worksheets in Workbook
'Loop through all worksheets
Dim ws As Worksheet
For Each ws In Worksheets
ws.Protect
Next ws
ws("TransReg").Select
End Sub
Which doesn’t work, more to the point the original macro will no longer work at all even after taking out the ‘ws("TransReg").Select’. In fact I have to close the unsaved file to restore the original macro which then works. I’ve tried it with Worksheets or Sheets to replace ws but the same result.
I'd appreciate your help
MikeRetyred
(Office 365 on MacMini macOS Mojave 10.14.6)
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try
Code:
[FONT='inherit']Sheets("TransReg").Select[/FONT]
 
Upvote 0
Try
Code:
[FONT='inherit']Sheets("TransReg").Select[/FONT]
Hi Fluff, I appreciate your interest.
I've had tried that same code, but it hadn't worked.
Since realised that to use ws as a variable and then to treat it as short for Sheets or Worksheets was daft of me, so you're right that I should have used Sheets, but only after I had found a way to terminate the preceding loop.
Regards
MikeRetyred
 
Upvote 0
Do you get any error messages?
 
Upvote 0
Don't know if it's the same for a mac, but normally you get a dialogue box appear that gives you an error number, error message & buttons "End", "Debug"
Don't you get that?
 
Upvote 0
Don't know if it's the same for a mac, but normally you get a dialogue box appear that gives you an error number, error message & buttons "End", "Debug"
Don't you get that?
Hi Fluff,
No error code although yes, the Debug message resulted in the yellow highlight of the line of code mentioned in my earlier post.
There do seem to be some differences between Excel in Office 365 on a Mac rather than on Microsoft's operating system/s - but I think this problem of mine, Microsoft can't be blamed - this one's down to me !
(I'm off to cook, cook, cook for a while, I'll re-open my computer tomorrow.)
Regards and thanks again for your interest
MikeRetyred
 
Upvote 0
You're welcome & sorry I couldn't have been more help.
 
Upvote 0
Hi Fluff,
Just out of interest this code seems to solve the problem (early morning cogitation rules ok:))

Sub ProtectWorkbookSheets()
Dim WS_Count As Integer
Dim I As Integer
' Since Worksheets are being added this sets WS_Count equal to the lastest number of worksheets.
WS_Count = Worksheets.Count
' Begin the loop.
For I = 1 To WS_Count
Worksheets(I).Protect
Next I
'Go to TransReg
Worksheets("TransReg").Select
Range("TR_TransDate").Select
End Sub

Really appreciated your interest yesterday.
Regards
Mike
 
Upvote 0
Glad you got it working & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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