I need to lock (make it read-only) some particular cells in my VBA macro. I do it the following way:
Range(Cells(begin_row, begin_column), Cells(final_row, final_column)).Select
If Selection.Locked = True Then
Selection.Locked = False
End If
ActiveSheet.Protect Contents:=True
It works, however I have two problems:
It appears that, while rows in the range (begin_row, final_row) are locked correctly, columns in that row range are locked not only in the range (begin_column, final_column) but anywhere else. Which is strange and undesired as an user may want to put some data or comment to the right from the frozen columns.
The columns titles could be quite long and an user may want to expand the column, however he cannot do it, as it is locked. So, I wonder: is it possible to lock only the content of the cells, yet make the cells themselves expandable? Or, if this is impossible, how to set the cell width in VBA or C# (the data is outputted from C# code actually)?
Thank you