ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   autosize cells (https://www.excelbanter.com/excel-programming/396010-autosize-cells.html)

bernd

autosize cells
 
Hello,

I've a worksheet with cells that are filled with a Hlookup function.
The problem is that sometimes the data in one cell is just one word
but other times 1000 words.

Is it possible to add a propery to the cell so that they are adjusted
to fit the content best? (I wan't them to be adjusted vertically)

Thanks,

Bernd


Dave Peterson

autosize cells
 
Maybe you can tie into that worksheet's calculation event to resize the rows.

If you want to try, right click on the worksheet that should have this
behavior. Select View code. Paste this into the code window:

Option Explicit
Private Sub Worksheet_Calculate()
application.enableevents = false
Me.Rows.AutoFit
'or be specific
Me.Rows("1:33").AutoFit
application.enableevents = true
End Sub

Changing the rowheight in some versions of excel (xl2003+, IIRC) will cause the
excel to want to recalc again. The .enableevents stuff stops excel from going
into a loop--recalc, loop, recalc, loop, ....

bernd wrote:

Hello,

I've a worksheet with cells that are filled with a Hlookup function.
The problem is that sometimes the data in one cell is just one word
but other times 1000 words.

Is it possible to add a propery to the cell so that they are adjusted
to fit the content best? (I wan't them to be adjusted vertically)

Thanks,

Bernd


--

Dave Peterson

bernd

autosize cells
 
thanks, works perfect!



All times are GMT +1. The time now is 07:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com