Error with Macro that Toggles Row height from default to Auto fit and back

sjliang

New Member
Joined
Aug 9, 2016
Messages
3
I originally found this thread and implemented this solution in my excel sheet with great success http://www.mrexcel.com/forum/excel-questions/726836-possible-collapse-cell-long-text.html to double click on a cell and toggle the row height from default (12.75 points) to autofit and back.

I then had issues with the macro not working for some users. I think it may be because the default row height is only 12.5 points for other people their own computer. I tried to edit the solution found in the link above to cover both if a row height was 12.75 OR 12.5 to expand to autofit as well as trying if the row height was <= 13 to autofit and neither of those worked.

Double clicking to collapse the rows still works just fine on the computers of people. How should I move forward? Any help would be greatly appreciated! Please and thanks :)
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
You might try something like this.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Static Flag As Boolean
    With Target
        If Flag Then
            .EntireRow.AutoFit
        Else
            .RowHeight = 12.75
        End If
    End With
    Cancel = True
    Flag = Not Flag
End Sub

Some times the Flag variable won't match what is on the sheet. If that happens, the user will think that they didn't double click properly, double click it again and the sheet will be the way that they want it.
 
Upvote 0
Flag is a static variable, so the routine "remembers" what it did the last time it was run, AutoFit or FixedHeight.
So, this time it will do the other thing.(it "forgets" if the workbook is closed)
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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