I want modify the code to allow users to format cloumns/rows in sheet array. Pl help.
[codebox]Sub Hide()
Dim strName As Variant
For Each strName In Array(“BG3”, “SSC”, “EXHAUST”, “MUFFLER”, “FRAME”, “RIM”, “HRD”, “PNG”, “ANS”)
With Worksheets(strName)
.Columns(“A:AR”).Hidden = True
.Protect Password:=”psd”
.Select
.Range(“AS1”).Select
End With
Next
Sheets(“Key Ratio “).Select
Range(“A3”).Select
End Sub[/codebox]
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Modification in code
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Modification in code
- This topic has 17 replies, 2 voices, and was last updated 15 years, 6 months ago.
AuthorTopicWSprasad
AskWoody LoungerOctober 14, 2009 at 5:04 am #463163Viewing 2 reply threadsAuthorReplies-
WSHansV
AskWoody LoungerOctober 14, 2009 at 5:09 am #1181204You can expand the line
.Protect Password:=”psd”
to specify what the user is allowed to do:
.Protect Password:=”psd”, AllowFormattingColumns:=True, AllowFormattingRows:=True
(If you omit AllowFormattingColumns and AllowFormattingColumns they are assumed to be False)
See the help for Protect for other available options.
-
WSprasad
AskWoody LoungerOctober 21, 2009 at 7:47 am #1182457You can expand the line
.Protect Password:=”psd”
to specify what the user is allowed to do:
.Protect Password:=”psd”, AllowFormattingColumns:=True, AllowFormattingRows:=True
(If you omit AllowFormattingColumns and AllowFormattingColumns they are assumed to be False)
See the help for Protect for other available options.
Thanks Hans. It is perfect.
For the sake of curiosity, is it possible to allow to format particular columns/rows instead of entire ws?
-
WSHansV
AskWoody Lounger -
WSprasad
AskWoody LoungerOctober 21, 2009 at 8:31 am #1182462What exactly do you want to accomplish?
In a wb, some columns, say A to Z are used as data field & Col. AA to AE are used as summary. The wb is protected & for review purpose, I keep the data fields hidden. With the help of above code, users are allowed to format col./rows as required. I want to restrict the users to format the summary portion only, if possible.
-
WSHansV
AskWoody Lounger -
WSprasad
AskWoody LoungerOctober 21, 2009 at 11:32 pm #1182550You can make it a bit more diffcult to unhide rows / columns by not allowing users to select locked cells. But I don’t think you can prevent it entirely. If you really want that, you shouldn’t allow users to format rows and columns.
Thanks Hans but as I stated, it is *NOT* necessarily required to hide particular columns & the code is perfect without any further modification. I was looking for the possibility of avoiding any mis-presentation but that can be taken care of without amending the code. (After all, the users are equally responsible for any (mis) presentation of data.)
Thanks again.
-
WSprasad
AskWoody LoungerOctober 23, 2009 at 1:47 am #1182712Thanks Hans but as I stated, it is *NOT* necessarily required to hide particular columns & the code is perfect without any further modification. I was looking for the possibility of avoiding any mis-presentation but that can be taken care of without amending the code. (After all, the users are equally responsible for any (mis) presentation of data.)
Thanks again.
Pl have a look :
[codebox]Sub unhide()
For Each sht In ActiveWorkbook.Sheets
On Error Resume Next
sht.Unprotect
If Err Then
MsgBox “Password incorrect. Please try again.”, vbExclamation
sht.Unprotect
If Err Then
MsgBox “Sorry! better luck next time”, vbExclamation
End If
End If
On Error GoTo 0
Next sht
Dim strName As Variant
For Each strName In Array(“BG3”, “SSC”, “MUFFLER”, “FRAME”, “RIM”, “HRD”, “PNG”, “ANS”)
With Worksheets(strName)
.Columns(“A:AP”).Hidden = False
.Select
.Range(“A1”).Select
End With
Next
Sheets(“Key Ratio “).Select
Range(“A3”).Select
End Sub[/codebox]1) if I hit the OR press cancel button instead of supplying the password, the code unprotect the sheet & jump to next sheet.
2) It is more convenient for me to unprotect all sheets in array in single attempt, instead of supplying password for each sheet one by one.
3) If I supplied correct password on second attempt, the code unprotect the sheet but msg still flashes.
Sorry if it sounds irretating but I have not tested the code this way before.
-
WSHansV
AskWoody Lounger -
WSprasad
AskWoody LoungerOctober 23, 2009 at 7:18 am #1182789Are all sheets protected?
No Hans, only sheets in array are protected using following code.
[codebox]ub Hide()
Dim strName As Variant
For Each strName In Array(“BG3”, “SSC”, “MUFFLER”, “FRAME”, “RIM”, “HRD”, “PNG”, “ANS”)
With Worksheets(strName)
.Columns(“A:AR”).Hidden = True
.Columns(“AU:AU”).Hidden = True
.Protect Password:=”psd”, AllowFormattingColumns:=True, AllowFormattingRows:=True
.Select
.Range(“AS1”).Select
End With
Next
Sheets(“Key Ratio “).Select
Range(“A3”).Select
End Sub[/codebox]Do all protected sheets have the same password?
Yes, all protected sheets have the same password.
-
WSHansV
AskWoody Lounger -
WSprasad
AskWoody LoungerOctober 23, 2009 at 7:48 am #1182793 -
WSHansV
AskWoody LoungerOctober 23, 2009 at 8:38 am #1182801Try this:
Code:Sub Unhide() Dim strPwd As String Dim strName As Variant ' Ask for password strPwd = InputBox("Please enter the password.") If Not strPwd = "psd" Then ' Give user another chance strPwd = InputBox("Password incorrect. Please try again.") If Not strPwd = "psd" Then ' Twice wrong - get out MsgBox "Sorry! Better luck next time.", vbExclamation Exit Sub End If End If ' Loop through protected sheets For Each strName In Array("BG3", "SSC", "MUFFLER", "FRAME", "RIM", "HRD", "PNG", "ANS") With Worksheets(strName) ' Unprotect .Unprotect Password:=strPwd ' Other actions .Columns("A:AP").Hidden = False .Select .Range("A1").Select End With Next strName ' Final actions Sheets("Key Ratio ").Select Range("A3").Select End Sub
-
-
-
-
-
WSprasad
AskWoody Lounger -
WSprasad
AskWoody Lounger -
WSHansV
AskWoody Lounger
-
Viewing 2 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
The 16-billion-record data breach that no one’s ever heard of
by
Alex5723
55 minutes ago -
Weasel Words Rule Too Many Data Breach Notifications
by
Nibbled To Death By Ducks
1 hour, 31 minutes ago -
Windows Command Prompt and Powershell will not open as Administrator
by
Gordski
4 hours, 46 minutes ago -
Intel Management Engine (Intel ME) Security Issue
by
PL1
7 hours, 43 minutes ago -
Old Geek Forced to Update. Buy a Win 11 PC? Yikes! How do I cope?
by
RonE22
1 hour, 53 minutes ago -
National scam day
by
Susan Bradley
56 minutes ago -
macOS Tahoe 26 the end of the road for Intel Macs, OCLP, Hackintosh
by
Alex5723
1 day, 1 hour ago -
Cyberattack on some Washington Post journalists’ email accounts
by
Bob99
1 day, 2 hours ago -
Tools to support internet discussions
by
Kathy Stevens
1 day, 9 hours ago -
How get Group Policy to allow specific Driver to download?
by
Tex265
17 hours, 40 minutes ago -
AI is good sometimes
by
Susan Bradley
1 day, 9 hours ago -
Mozilla quietly tests Perplexity AI as a New Firefox Search Option
by
Alex5723
23 hours, 49 minutes ago -
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
2 days, 10 hours ago -
June KB5060842 update broke DHCP server service
by
Alex5723
2 days, 8 hours ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
2 days, 12 hours ago -
Excessive security alerts
by
WSSebastian42
1 day, 3 hours ago -
* CrystalDiskMark may shorten SSD/USB Memory life
by
Alex5723
2 days, 22 hours ago -
Ben’s excellent adventure with Linux
by
Ben Myers
15 hours, 15 minutes ago -
Seconds are back in Windows 10!
by
Susan Bradley
2 days, 9 hours ago -
WebBrowserPassView — Take inventory of your stored passwords
by
Deanna McElveen
1 day, 2 hours ago -
OS news from WWDC 2025
by
Will Fastie
12 hours, 59 minutes ago -
Need help with graphics…
by
WSBatBytes
1 day, 17 hours ago -
AMD : Out of Bounds (OOB) read vulnerability in TPM 2.0 CVE-2025-2884
by
Alex5723
3 days, 13 hours ago -
Totally remove or disable BitLocker
by
CWBillow
2 days, 12 hours ago -
Windows 10 gets 6 years of ESU?
by
n0ads
2 days, 15 hours ago -
Apple, Google stores still offer China-based VPNs, report says
by
Nibbled To Death By Ducks
4 days ago -
Search Forums only bring up my posts?
by
Deo
5 hours, 14 minutes ago -
Windows Spotlight broken on Enterprise and Pro for Workstations?
by
steeviebops
1 hour, 48 minutes ago -
Denmark wants to dump Microsoft for Linux + LibreOffice
by
Alex5723
16 hours, 12 minutes ago -
How to get Microsoft Defender to honor Group Policy Setting
by
Ralph
9 hours, 12 minutes ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.