Stange .RowHeight results

tschop

New Member
Joined
Dec 15, 2014
Messages
13
I have a very simple routine that uses:

ThisWorkbook.Worksheets(proposal).Range("B" & a).EntireRow.RowHeight = 17

to set the row height to 17. When the above line of code executes, it sets the row height to 22 instead of 17.

I have two other identical lines of code that should set the row heights to 35 and 46. They instead set the row heights to 46 and 61 respectively.

Can anyone tell me what is going on with this?

Thanks,

Tom
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

tschop

New Member
Joined
Dec 15, 2014
Messages
13
Code:
For a = TandC + 1 To TandC + b + 7
                If Len(ThisWorkbook.Worksheets(proposal).Range("B" & a).value) > 0 Then
                    lentest1 = Len(ThisWorkbook.Worksheets(proposal).Range("B" & a).value)
                    lentest2 = GetPixelLen.GetStringPixelWidth(ThisWorkbook.Worksheets(proposal).Range("B" & a).value, "Arial", 8)
                    If lentest2 > 0 Then
                        If lentest2 > 634 Then
                            If lentest2 > 1268 Then
                                If lentest2 > 1902 Then
                                    
                                Else
                                    ThisWorkbook.Worksheets(proposal).Range("B" & a).EntireRow.RowHeight = 46
                                End If
                            Else
                                ThisWorkbook.Worksheets(proposal).Range("B" & a).EntireRow.RowHeight = 35
                            End If
                        Else
                            ThisWorkbook.Worksheets(proposal).Range("B" & a).EntireRow.RowHeight = 17
                        End If
                    Else
                        ThisWorkbook.Worksheets(proposal).Range("B" & a).EntireRow.RowHeight = 17
                    End If
                End If
            Next a
 

tschop

New Member
Joined
Dec 15, 2014
Messages
13
For the above code, I am finding the length of a string in pixels to decide how high to set the row height on a collection of merged cells. Based on the number of pixels the string is long, I can determine whether it needs to be 17, 35, or 46 pixels high.

I am doing this because autofit does not work on merged cells.

The function GetStringPixelWidth returns the number of pixels that the string is long.
 

Special-K99

Well-known Member
Joined
Nov 7, 2006
Messages
8,341
I'm wondering what would happen if you copied this code and the dependent data to a new workbook and tested it there.
Or possibly just copied the all the data from the dependent sheet to a blank workbook.
Wondering if it's smethign to do with the actual workbook.
 

Watch MrExcel Video

Forum statistics

Threads
1,089,898
Messages
5,411,094
Members
403,341
Latest member
April2020

This Week's Hot Topics

Top