Automatically updating row height upon cell selection (without losing undo stack)

coraltea

New Member
Joined
Jul 1, 2020
Messages
12
Office Version
  1. 2016
Platform
  1. Windows
RickXL posted a great code that uses vba to change the row height of the selected row. See Code:

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static iRow As Long
If Target.Rows.Count > 1 Then Exit Sub
If iRow > 0 Then
Rows(iRow).Rowheight = 20
End If
iRow = Target.Row
Target.RowHeight = 40
End Sub

I essentially just use this code to make the selected record more readable due to the long entries that some of the cells contain. The only drawback from this code is that it clears the undo stack from excel so any time that I have a selection change it is permanent. Is there a work around that would allow me to keep the undo stack?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Would formatting the cells to wrap text give you the same result?
 
Upvote 0
The cells are already formatted to wrap the text. The column widths must remain the same which isn't very wide. I could just have all the rows expanded really large but that makes the spread sheet very clunky and difficult to scroll through with the standard 3 row scroll. Being able to keep all the rows that I'm not looking at standard height while expanding the current row would help with 1) reading record entries and 2) tracking which record I'm editing as the table can be quite large.
 
Upvote 0
Is there something that I can provide to help clarify the question? I'm not getting any responses.
 
Upvote 0
You're probably not getting any responses because when VBA interacts with a sheet it automatically wipes out the Undo stack.
 
Upvote 0
Unfortunately, I think you are stuck with it.
Either use the macro & loose the stack, or keep the stack & don't use the macro.
 
Upvote 0
The question is perfectly clear
Unfortunately running VBA, the way you require, kills undo and that's it
 
Upvote 0
I was afraid of that. Thanks for the quick responses. I'll have to try to find some other work around.
 
Upvote 0

Forum statistics

Threads
1,214,594
Messages
6,120,436
Members
448,964
Latest member
Danni317

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