Results 1 to 1 of 1

Autofit Script locks cells in a Protected Sheet

Threaded View

lbrun01 Autofit Script locks cells in... 08-05-2013, 04:43 PM
  1. #1
    Registered User
    Join Date
    08-05-2013
    Location
    Davenport, Iowa
    MS-Off Ver
    Excel 2010
    Posts
    1

    Autofit Script locks cells in a Protected Sheet

    I am using VBA to autofit text within cells. It works great until I protect the sheet. When I enter text in an "unlocked" cell in the protected sheet, the cells autofits the data correctly however then the cells becomes "locked". I cannot go back to update the content. Does anyone have suggestions on how to fix the issue? I am using the script below:
     
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim NewRwHt As Single
    Dim cWdth As Single, MrgeWdth As Single
    Dim c As Range, cc As Range
    Dim ma As Range
    
    With Target
    If .MergeCells And .WrapText Then
    If ProtectStatus Then Me.Unprotect
    Set c = Target.Cells(1, 1)
    cWdth = c.ColumnWidth
    Set ma = c.MergeArea
    For Each cc In ma.Cells
    MrgeWdth = MrgeWdth + cc.ColumnWidth
    Next
    Application.ScreenUpdating = False
    On Error Resume Next
    ma.MergeCells = False
    c.ColumnWidth = MrgeWdth
    c.EntireRow.AutoFit
    NewRwHt = c.RowHeight
    c.ColumnWidth = cWdth
    ma.MergeCells = True
    ma.RowHeight = NewRwHt
    cWdth = 0: MrgeWdth = 0
    On Error GoTo 0
    Application.ScreenUpdating = True
    End If
    End With
    End Sub
    Last edited by lbrun01; 08-05-2013 at 07:12 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Script/Macro to Sort Protected Cells with AutoFilters
    By cabenjam in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-25-2012, 12:34 AM
  2. Delete rows in a protected sheet with protected cells
    By Maranwe in forum Excel General
    Replies: 7
    Last Post: 10-31-2011, 08:12 AM
  3. Me.Rows.Autofit with a Protected Sheet not working.
    By mrgillus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-23-2009, 09:55 AM
  4. Excel VB script which locks cell after single use in shared work book
    By yashwanth2014 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-16-2008, 02:20 PM
  5. Autofit Columns on linked and protected sheet
    By Paul Sheppard in forum Excel General
    Replies: 0
    Last Post: 10-08-2008, 09:59 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1