A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Autofit single cell text



 
 
Thread Tools Display Modes
  #1  
Old October 7th, 2008, 03:43 PM posted to microsoft.public.excel.misc
Jay
external usenet poster
 
Posts: 704
Default Autofit single cell text

I am trying to autofit rows, all of which one column has cells that contain
anywhere from 0 - 1500 characters. No cells are merged on the worksheet. Each
of these cells with content have manual linebreaks in them to designate
seperate entries (each line contains an action completed on a certain date).
These lines within a cell may contain 10 characters or 100. Autofitting works
about 75% of the time, while the other 25% of the time it will cut off
several lines at the bottom (without maxing out at a row height of 409).

I have created a (admittedly crude) macro to calculate rowheight based on
static font size (in this case) and an assumption that each line takes up
~75% of the column.
Rowheight = (Amount of chars * determined character height ) / chars per
column

The problem with this is there is usually a fair bit of white space at the
bottom of the cells (wasting paper), and in specialy circumstances could
still cut of cells if many entries are short (ie take up less column space).

Is there anyway to get autofit to work 100% of the time and not cut of rows
(preferable) or a better method of "manually autofitting".


Here is a snippet from the code where the "autofitting" is done:

Do
'Determines if this row has information
emptyRow = IsEmpty(Range("A" & rowNum).Value)

'If this row contains information
If emptyRow = False Then
Rows(rowNum & ":" & rowNum).EntireRow.AutoFit

'Calculate amount of characters in cell
Range("M" & rowNum).FormulaR1C1 = "=LEN(RC[-1])"

'Theoretical row height with ~75% of column used up (55 units)
and line height of 14 chars
rowHeightTest = (Range("M" & rowNum).Value * 14) / 40

'If theoretical number is greater than autofit number
If rowHeightTest Rows(rowNum & ":" & rowNum).RowHeight Then

'Failsafe if theoretical number is greater than max.
If rowHeightTest 409 Then rowHeightTest = 409
Rows(rowNum & ":" & rowNum).RowHeight = rowHeightTest
End If

'Clean up temp. cells and cycle to next cell
Range("M" & rowNum).ClearContents
rowNum = rowNum + 1
End If

Loop Until emptyRow = True
  #2  
Old October 7th, 2008, 04:43 PM posted to microsoft.public.excel.misc
Joel
external usenet poster
 
Posts: 2,855
Default Autofit single cell text

Try changing the vertical allignment to TOP.

Format - Cells - Allignment - Verticle - Top

"Jay" wrote:

I am trying to autofit rows, all of which one column has cells that contain
anywhere from 0 - 1500 characters. No cells are merged on the worksheet. Each
of these cells with content have manual linebreaks in them to designate
seperate entries (each line contains an action completed on a certain date).
These lines within a cell may contain 10 characters or 100. Autofitting works
about 75% of the time, while the other 25% of the time it will cut off
several lines at the bottom (without maxing out at a row height of 409).

I have created a (admittedly crude) macro to calculate rowheight based on
static font size (in this case) and an assumption that each line takes up
~75% of the column.
Rowheight = (Amount of chars * determined character height ) / chars per
column

The problem with this is there is usually a fair bit of white space at the
bottom of the cells (wasting paper), and in specialy circumstances could
still cut of cells if many entries are short (ie take up less column space).

Is there anyway to get autofit to work 100% of the time and not cut of rows
(preferable) or a better method of "manually autofitting".


Here is a snippet from the code where the "autofitting" is done:

Do
'Determines if this row has information
emptyRow = IsEmpty(Range("A" & rowNum).Value)

'If this row contains information
If emptyRow = False Then
Rows(rowNum & ":" & rowNum).EntireRow.AutoFit

'Calculate amount of characters in cell
Range("M" & rowNum).FormulaR1C1 = "=LEN(RC[-1])"

'Theoretical row height with ~75% of column used up (55 units)
and line height of 14 chars
rowHeightTest = (Range("M" & rowNum).Value * 14) / 40

'If theoretical number is greater than autofit number
If rowHeightTest Rows(rowNum & ":" & rowNum).RowHeight Then

'Failsafe if theoretical number is greater than max.
If rowHeightTest 409 Then rowHeightTest = 409
Rows(rowNum & ":" & rowNum).RowHeight = rowHeightTest
End If

'Clean up temp. cells and cycle to next cell
Range("M" & rowNum).ClearContents
rowNum = rowNum + 1
End If

Loop Until emptyRow = True

  #3  
Old October 7th, 2008, 05:06 PM posted to microsoft.public.excel.misc
Jay
external usenet poster
 
Posts: 704
Default Autofit single cell text

Joel,

Thanks for the reply. I have tried several vertical alignment options (top,
bottom & distributed) and it doesn't fix the problem.

"Joel" wrote:

Try changing the vertical allignment to TOP.

Format - Cells - Allignment - Verticle - Top

  #4  
Old October 7th, 2009, 08:47 PM posted to microsoft.public.excel.misc
Luke Phillips
external usenet poster
 
Posts: 1
Default Autofit single cell text - Ja

I know that this post is a year old today but I must find a solution for this issue. Did you ever find a fix for this? It is driving me crazy!



Ja wrote:

Autofit single cell text
07-Oct-08

I am trying to autofit rows, all of which one column has cells that contain
anywhere from 0 - 1500 characters. No cells are merged on the worksheet. Each
of these cells with content have manual linebreaks in them to designate
seperate entries (each line contains an action completed on a certain date).
These lines within a cell may contain 10 characters or 100. Autofitting works
about 75% of the time, while the other 25% of the time it will cut off
several lines at the bottom (without maxing out at a row height of 409).

I have created a (admittedly crude) macro to calculate rowheight based on
static font size (in this case) and an assumption that each line takes up
~75% of the column.
Rowheight = (Amount of chars * determined character height ) / chars per
column

The problem with this is there is usually a fair bit of white space at the
bottom of the cells (wasting paper), and in specialy circumstances could
still cut of cells if many entries are short (ie take up less column space).

Is there anyway to get autofit to work 100% of the time and not cut of rows
(preferable) or a better method of "manually autofitting".


Here is a snippet from the code where the "autofitting" is done:

Do
'Determines if this row has information
emptyRow = IsEmpty(Range("A" & rowNum).Value)

'If this row contains information
If emptyRow = False Then
Rows(rowNum & ":" & rowNum).EntireRow.AutoFit

'Calculate amount of characters in cell
Range("M" & rowNum).FormulaR1C1 = "=LEN(RC[-1])"

'Theoretical row height with ~75% of column used up (55 units)
and line height of 14 chars
rowHeightTest = (Range("M" & rowNum).Value * 14) / 40

'If theoretical number is greater than autofit number
If rowHeightTest Rows(rowNum & ":" & rowNum).RowHeight Then

'Failsafe if theoretical number is greater than max.
If rowHeightTest 409 Then rowHeightTest = 409
Rows(rowNum & ":" & rowNum).RowHeight = rowHeightTest
End If

'Clean up temp. cells and cycle to next cell
Range("M" & rowNum).ClearContents
rowNum = rowNum + 1
End If

Loop Until emptyRow = True

EggHeadCafe - Software Developer Portal of Choice
AJAX enabled web page design and beginner?s concept
http://www.eggheadcafe.com/tutorials...-page-des.aspx
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:42 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.