Unable to Set Row Height after Running New Macro

DavCode

New Member
Joined
Apr 2, 2023
Messages
15
Office Version
  1. 2013
Platform
  1. Windows
The following code was working fine:

Private Sub Show_Hide_Toggle_Top_Info_Rows()
Application.ScreenUpdating = False

On Error Resume Next

If Rows("5:5").RowHeight > 0.25 Then
Rows("5:18").RowHeight = 0.25
Else
Rows("5:18").RowHeight = 18
End If

Range("a1").Select
Application.ScreenUpdating = True

End Sub

I introduced a new procedure that also works fine, but subsequently prevents the first macro from working (after the new macro is successfully run). The error message is 'Unable to Set RowHeight property of range class'.

The new macro (causing the problem) is:
Private Sub Reserve()

Dim myRange As Range
Dim myCell As Range

Sheets("E").Unprotect ""
Set myRange = Sheets("E").Range("$d$23:$d$522")

For Each myCell In myRange
If IsEmpty(myCell) Then
Else
myCell.Offset(0, 27).Value = "y"
Sheets("E").Range("$af$21").Copy
myCell.Offset(0, 28).PasteSpecial Paste:=xlPasteValues
myCell.Locked = True
myCell.Interior.ColorIndex = 24
End If
Next myCell
Sheets("E").Protect ""

End Sub
I am guessing it might have something to do with locking the cells but the locked range is below the rows that have height changes applied.

Thanks..
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Have you unlocked all the cells on the sheet before running your new code? as all cells are set as locked by default, so when you protect the sheet those cells are locked as well as the one's you are specifically locking in the code.

The other (more normal way) is to unprotect the sheet at the start of the Show_Hide_Toggle_Top_Info_Rows macro and reset the protection at the end of the macro

3rd way is to set the UserInterfaceOnly to True when protecting the sheet
 
Upvote 0
Solution
Hi MARK858,

You're response triggered my memory - I forgot to add AllowFormattingRows:=True to the password protect line.
I prefer not to 'unprotect' the sheet when toggling the top row 'hide (row height = 0.25)/unhide (row height=18)' macro-assigned 'button', if it's not necessary.
I have used UserInterfaceOnly with Enable.Outlining to enable the expand/collapse feature in Excel.

Thanks!
 
Upvote 0
I take it that you are sorted now?
 
Upvote 0

Forum statistics

Threads
1,215,105
Messages
6,123,114
Members
449,096
Latest member
provoking

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