how to auto adjust cell height based on text

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
563
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
On my userform I multi line textbox that only allows 250 characters. Instead of the user typing in text the normal way, like the following:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

They are copying and pasted the text into the textbox so it looks like the following:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.


In order to see the entire entry in the cell, the user would have to expand the cell height. I have included the section of code that would be handling this task and I have already tried the following way, but this did not work. From what I can see, the sheet/cells are not protected. Any advice would be greatly appreciated. Thank you.

VBA Code:
    If rngItem.Offset(, 3).Value = "" Then
        rngItem.Offset(, 3).Select
        rngItem.Offset(, 3).Value = Me.txtbxDescription.Value
        With Selection
            .Rows.AutoFit
        End With
    End If
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I just tried the following with no luck. I changed this:
VBA Code:
With Selection
     .Rows.AutoFit
End With
to this
Code:
rngItem.Offset(, 3).Rows.AutoFit
I realize it is the same thing but I am trying anything that I can think of that might work.
 
Upvote 0
Try
VBA Code:
rngItem.EntireRow.AutoFit
 
Upvote 0
That did not work. When it got to your line of code while I was stepping through it, nothing happened. No error messages or anything else. So I even modified your code with following to match what I previously posted:
VBA Code:
rngItem.Offset(, 3).EntireRow.AutoFit
and
Code:
With Selection
    .EntireRow.AutoFit
End With
Is there something that I need to look for that would prevent this from working? I decided to post the entire Private Sub. Maybe there is something there that may cause this not to work. Thank you Fluff.
Code:
Private Sub cmdbtnEnter_Click()
           
    lastRow = Range("C33").End(xlUp).Row + 1
    If rngItem Is Nothing Then
        Set rngItem = Cells(lastRow, "C")
    ElseIf Not rngItem Is Nothing Then
        Set rngItem = Cells(lastRow, "C")
    End If
    If rngItem.Value = "" Then
        rngItem.Select
        rngItem.Value = Me.txtbxQuantity.Value
    End If
    If rngItem.Offset(, 1).Value = "" Then
        rngItem.Offset(, 1).Select
        rngItem.Offset(, 1).Value = Me.txtbxItmNmbr.Value
    End If
    If rngItem.Offset(, 3).Value = "" Then
        rngItem.Offset(, 3).Select
        rngItem.Offset(, 3).Value = Me.txtbxDescription.Value
        'rngItem.Offset(, 3).EntireRow.AutoFit
        'With Selection
        '   .EntireRow.AutoFit
        'End With
    End If
    If rngItem.Offset(, 9).Value = "" Then
        rngItem.Offset(, 9).Select
        rngItem.Offset(, 9).Value = Me.txtbxUntCst.Value
    End If
    If answ > 0 Then
       UserForm_Initialize
    Else
        Unload Me
    End If
End Sub
 
Upvote 0
Do you Wrap Text enabled for that cell?
 
Upvote 0
Yes they are wrapped. Also my apologies, but there is one very important thing that I forgot to mention which may solve this issue. That row is a merged cell column F thru K.
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,974
Members
448,934
Latest member
audette89

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