×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Excel: When Cell Height is 409.5, create & merge with new Row

Excel: When Cell Height is 409.5, create & merge with new Row

Excel: When Cell Height is 409.5, create & merge with new Row

(OP)
Hi there!
New to VBA and I'm trying to figure this out. This is an issue I need to automate.

Sometimes I have too much text in a cell, and it doesn't fit inside the max Cell Height of 409.5. I'd like to run a script that identifies when a cell's height is 409.5, inserts a row below, merges those two rows, and then Autofits the height. The goal is that all of my text should be visible in the cell.

Any help would be appreciated, thank you very much!

RE: Excel: When Cell Height is 409.5, create & merge with new Row

(OP)
Thanks Andrzejek, but that isn't helpful. Would appreciate anyone else's input to this question. It seems to be a common issue for excel users.

RE: Excel: When Cell Height is 409.5, create & merge with new Row

AutoFit will not work in merged cells.

This is how to get the merge to work, though...

CODE

Private Sub Worksheet_Change(ByVal Target As Range)
    
    With Target
        .EntireRow.AutoFit
        
        If .MergeCells Then
            'cell is already merged
        Else
            If .RowHeight > 409.5 Then
                Application.EnableEvents = False
                .Offset(-1, 0).EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
                Range(.Cells(1, 1), .Cells(2, 1)).Merge
                Application.EnableEvents = True
            End If
            'AutoFit will not function with merged cells
            Rows.AutoFit
        End If
    End With
End Sub 

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: Excel: When Cell Height is 409.5, create & merge with new Row

>AutoFit will not work in merged cells.

Indeed not - but you can write your own with the use of a richtext control and EM_FORMATTEXT

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close