Tabbing Issue after macro runs on selected cell

Joined
Dec 14, 2009
Messages
1
Reaction score
0
Good Afternoon Everyone and thanks in advance for any help you can give me on this issue! I am by no means an expert at Excel Macros, but I'm doing my best to work through this one.
I have a user that created an Excel form, this form is a protected worksheet with comments sections that were created using merged cells (not my choice). As we all know when a document is protected excel can't automatically expand merged cells to fit the text. I have added a macro that runs when a user changes fields on the form. When the user exits a comments field the macro basically unprotects the document, expands the row with the merged comments cell, and re-protects the document.
So, here's the problem, when filling out the form if the user enters a comment and hits tab the macro runs. In my macro code the comments field will be re-selected automatically when the macro if finished running. I had to re-select the comments field in order to make sure it would be unlocked after the macro finished running. But, after the macro runs if the user then tries to tab to the next field the tabbing order seems to be messed up because it skips a field. For example if fields A1, A2, and A3 were unlocked fields and the macro had just ran on field A1 if the user then hit tab they would be taken to field A3, completely skipping filed A2. I'm at a loss as to what is causing this or how to fix it. Can anyone please help? The macro code is posted below.
Code:
 Private Sub Worksheet_Change(ByVal Target As Range) [/font][/left]
[left][font=Arial]If Target.Address = "$A$55" Or Target.Address = "$G$65" Or Target.Address = "$G$67" Or Target.Address = "$G$69" Or Target.Address = "$G$71" Or Target.Address = "$G$73" Or Target.Address = "$A$83" Or Target.Address = "$E$83" Or Target.Address = "$I$83" Or Target.Address = "$A$84" Or Target.Address = "$E$84" Or Target.Address = "$I$84" Or Target.Address = "$A$85" Or Target.Address = "$E$85" Or Target.Address = "$I$85" Or Target.Address = "$A$88" Then[/font][/left]
[left][font=Arial][/font] [/left]
[left][font=Arial]Dim NewRwHt As Single[/font][/left]
[left][font=Arial]Dim cWdth As Single, MrgeWdth As Single[/font][/left]
[left][font=Arial]Dim c As Range, cc As Range[/font][/left]
[left][font=Arial]Dim ma As Range[/font][/left]
[left][font=Arial]Dim OrigRwHt[/font][/left]
[left][font=Arial]ActiveSheet.Unprotect Password:="88"[/font][/left]
[left][font=Arial]With Target[/font][/left]
[left][font=Arial]If .MergeCells And .WrapText Then[/font][/left]
[left][font=Arial]Set c = Target.Cells(1, 1)[/font][/left]
[left][font=Arial]cWdth = c.ColumnWidth[/font][/left]
[left][font=Arial]Set ma = c.MergeArea[/font][/left]
[left][font=Arial]For Each cc In ma.Cells[/font][/left]
[left][font=Arial]MrgeWdth = MrgeWdth + cc.ColumnWidth[/font][/left]
[left][font=Arial]Next[/font][/left]
[left][font=Arial]Application.ScreenUpdating = False[/font][/left]
[left][font=Arial]ma.MergeCells = False[/font][/left]
[left][font=Arial]OrigRwHt = c.RowHeight[/font][/left]
[left][font=Arial]c.EntireRow.AutoFit[/font][/left]
[left][font=Arial]If c.RowHeight < OrigRwHt Then[/font][/left]
[left][font=Arial]NewRwHt = OrigRwHt[/font][/left]
[left][font=Arial]Else[/font][/left]
[left][font=Arial]NewRwHt = c.RowHeight[/font][/left]
[left][font=Arial]End If[/font][/left]
[left][font=Arial]c.ColumnWidth = MrgeWdth[/font][/left]
[left][font=Arial]c.ColumnWidth = cWdth[/font][/left]
[left][font=Arial]ma.MergeCells = True[/font][/left]
[left][font=Arial]ma.RowHeight = NewRwHt[/font][/left]
[left][font=Arial]cWdth = 0: MrgeWdth = 0[/font][/left]
[left][font=Arial]Application.ScreenUpdating = True[/font][/left]
[left][font=Arial]End If[/font][/left]
[left][font=Arial]End With[/font][/left]
[left][font=Arial]Range(Target.Address).Select[/font][/left]
[left][font=Arial]Selection.Locked = False[/font][/left]
[left][font=Arial]ActiveSheet.Protect DrawingObjects:=True, _[/font][/left]
[left][font=Arial]Contents:=True, Scenarios:=True, Password:="88"[/font][/left]
[left][font=Arial]End If[/font][/left]
[left][font=Arial]End Sub[/font][/left]
[left][font=Arial]
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top