Row Height adjusted based on content via code or Macro

SBass

New Member
Joined
Oct 11, 2017
Messages
17
I have a worksheet that contains two cells that are populated via a series of nested IF statements based on the contents of another cell. The issue is that one of the statements generates a MUCH longer text string than the other two options. To make the text appear aesthetically pleasing, the rows need to be at a height of 40 for the longer string, but only 15 for the other strings. I realize that I can't accomplish this with conditional formatting, but there has to be a way to do it. I'm open to ideas/suggestions, even if it includes simple code or a macro.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
The following macro will set the 'Wraptext' feature to "True" changing the row one height to fit the text.
Code:
Sub test()
    Range("A1").WrapText = True
End Sub
 
Upvote 0
I have the Text Wrap turned on for the cells, but it is not adjusting the row height for those two cells only. It does it in all other cells. I think that is because we don't actually manually enter data in those cells, because I believe that is when that adjustment is normally made in Excel.
 
Upvote 0
Unfortunately, Text Wrap affects the whole row.
 
Upvote 0
Maybe I didn't explain my question clearly. Cell A73 populates based on the content of B8. There are 3 options that it will populate with. 2 are short & the same length, but the 3rd is 3 times as long. What I want is for Excel to adjust the cell height when that 3rd option is the one that fills cell A73.
 
Upvote 0
Is the contents of B8 entered manually or is it the result of a formula? Can you tell me the length of the 2 shorter options including any spaces?
 
Upvote 0
The contents of B8 is populated using a data validation drop-down. The options for A73 are either 9 characters or 62 character's (with spaces).
 
Upvote 0
Copy and paste this macro into the worksheet code module. Do the following: right click the tab for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Make a selection in B8.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("B8")) Is Nothing Then Exit Sub
    If Len(Target) > 9 Then
        Range("A73").WrapText = True
    End If
    Range("A73") = Target
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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