Forum Discussion
SamFares40
Apr 15, 2020Copper Contributor
VBA to hide set of columns is in conflict with protecting the sheet
Hello,
i created VBA to hide a set of columns. But when i try to protect certain cells in sheet including the columns that will be hiden, i get the error message" Run time error1004, Unable to set the hidden property of the Range class".
I am not sure how to fix it or if there is a better way to do it.
Regards,
Sam
To achieve your desired functionality in Excel for the web, you can use a combination of formulas and data validation.
Here is a step-by-step guide:
- Set up your columns:
- Column A: Admission Date
- Column B: Number of Weeks
- Column C: Departure Date (auto-calculated)
- Enter your formula for the Departure Date:
- In cell C2, enter the formula =IF(AND(A2<>"",B2<>""), A2+(B2*7), ""). This formula checks if both the Admission Date and Number of Weeks are entered. If they are, it calculates the Departure Date; otherwise, it leaves the cell blank.
- Set up data validation for the Number of Weeks column:
- Select the cells in column B where you will enter the number of weeks (e.g., B2:B100).
- Go to the Data tab on the ribbon.
- Click on Data Validation.
- Choose Whole Number in the Allow dropdown.
- In the Data box, select Between and enter 1 and the maximum number of weeks allowed.
- Click OK to apply the data validation.
With this setup, users can enter the Admission Date and Number of Weeks, and the Departure Date will automatically calculate when they either move to another cell or press Enter. Data validation ensures that only whole numbers are entered for the Number of Weeks.
This approach should work in Excel for the web, allowing for automatic calculation of the Departure Date based on the Admission Date and Number of Weeks.Formularbeginn The text and steps was created with the help of AI.
Hope this will help you.
Was the answer useful? Mark as best response and like it!
This will help all forum participants.
3 Replies
Sort By
- JKPieterseSilver ContributorWhen you protect a worksheet, one of the options is to allow "Format Columns". If you check that box you can hide and unhide columns on a protected sheet.
- RRuesenbergCopper Contributor
JKPieterse - When i select that setting feature it works while i am in the document. Even after saving, i open the document again the setting default back. I can not unhide and hide columns
- SamFares40Copper Contributor
JKPieterse Thank you Jan!