Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help on Auto Formating Row Heights 2

Status
Not open for further replies.

JTBorton

Technical User
Jun 9, 2008
345
DE
I am working on a project that will take an array of information from a user form, write it onto a new spreadsheet and format it depending on the data. Some of the cells may have very long text strings. The column width is fixed and I want to row height to vary, with wrap around text on.

I tried the following
With Sheets(shtName)
(The code formats the sheet depending on the data)
.rows(V).AutoFit
End with

How ever the row is not auto-sized to the height of the cell with the longest string of Data. It instead cuts it off and sizes the rows to the standard size that they start at when you create a new sheet. The only other thing I can think of is to set different heights based on the size of the string, such as

Select Case len(string)
Case > 25
rows(v).RowHeight = #
Case > 15
rows(v).rowheight = #
.
.
.
End Select

Any ideas?
 





Hi,

Do you have MERGED CELLS?

AutoFit does not do well with merged cells.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Also ensure that Wrap Text is enabled.

Code:
With Cells
    .WrapText = True
    .EntireRow.AutoFit
End With

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ 181-2886 before posting.
 
Wrap text is enabled. And yes I have merged cells. Is there a way to work around that or do I need to unmerge them for it to work properly?
 




"AutoFit does not do well with merged cells."

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 




Actually, merged cells works at odds with many spreadsheet-related features of Excel, and I would not recommend using in most cases.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
If you like the look of merged cells, you can use Center Across Selection instead. 'Gives you the look without the headaches.

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ 181-2886 before posting.
 
I has a problem formatting column widths when some rows had merged cells. I found that if I formatted the column widths before merging the cells it seemed to work.

sam

 

mscallisto

I tried autofitting before merging the cells and it worked - until I merged the cells. Then it squashed them again.

anotherhiggins

How do I use the center across selection property?
 





Select the cells that you want to center on, LEFT TO RIGHT.

Format > Cells > Allignment Tab: Horizontal select Center across selection

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Oh yes thats one way. But my question is how do you code it? I want the program to automatically format the cells as it adds information, and only format cells with information.

like
.Range("a4.h3").HorizontalAlignment = xlCenter

I tried
.Range("a4.h3").HorizontalAlignment = xlCenterAcrossSelection
but that didn't work

I wish I could find a big table with all the properties and their parameters in VBA along with a short description of what they do. Microsoft Visual Basic Help is rather limited in its information.

I really appreciate all the help
 





.Range("a4.h3") is incorrect syntax.
Code:
.Range("a3:h4")
both the ROW precidence and the DOT were incorrect.

Use your macro recorder to get better code.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top