Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
MarkN
 
Posts: n/a
Default Wrap text in column headers to fit text in column

Hello,

I get about forty columns of data dumped into an Excel sheet every month.
The column headers at the top of the columns are usually considerably wider
than the data in the columns. I want to wrap the header text in each column
so that it is as wide as the widest entry in the rest of that column. Each
column width is diferent.

If anybody knows a quick method of doing this, it would save me a lot of time.
--
Thanks,
MarkN
  #2   Report Post  
Rowan Drummond
 
Posts: n/a
Default Wrap text in column headers to fit text in column

Maybe with a macro. Assuming your headers are in row 1:

Sub header()
Dim eCol As Integer
Dim i As Integer
Dim head As String
eCol = Cells(1, Columns.Count).End(xlToLeft).Column
For i = 1 To eCol
With Cells(1, i)
head = .Value
.ClearContents
.EntireColumn.AutoFit
.WrapText = True
.Value = head
End With
Next i
End Sub

Hope this helps
Rowan

MarkN wrote:
Hello,

I get about forty columns of data dumped into an Excel sheet every month.
The column headers at the top of the columns are usually considerably wider
than the data in the columns. I want to wrap the header text in each column
so that it is as wide as the widest entry in the rest of that column. Each
column width is diferent.

If anybody knows a quick method of doing this, it would save me a lot of time.

  #3   Report Post  
Marcus Ahlbäck
 
Posts: n/a
Default Wrap text in column headers to fit text in column

Hello

Try this:

1) select the entire area except the heading row (i e typically row 2 and
downwards)

2) Format, Column, Autofit selection

3) select heading row (only)

4) Format, Cells, Alignment, Wrap text

Kind regards Marcus


"MarkN" wrote:

Hello,

I get about forty columns of data dumped into an Excel sheet every month.
The column headers at the top of the columns are usually considerably wider
than the data in the columns. I want to wrap the header text in each column
so that it is as wide as the widest entry in the rest of that column. Each
column width is diferent.

If anybody knows a quick method of doing this, it would save me a lot of time.
--
Thanks,
MarkN

  #4   Report Post  
Jim May
 
Posts: n/a
Default Wrap text in column headers to fit text in column

Neat Rowan; Is there a way to "nudge-up" the spacing
a few more characters "above the standard "autofit amt?
If so, how?
TIA,

"Rowan Drummond" wrote in message
...
Maybe with a macro. Assuming your headers are in row 1:

Sub header()
Dim eCol As Integer
Dim i As Integer
Dim head As String
eCol = Cells(1, Columns.Count).End(xlToLeft).Column
For i = 1 To eCol
With Cells(1, i)
head = .Value
.ClearContents
.EntireColumn.AutoFit
.WrapText = True
.Value = head
End With
Next i
End Sub

Hope this helps
Rowan

MarkN wrote:
Hello,

I get about forty columns of data dumped into an Excel sheet every month.
The column headers at the top of the columns are usually considerably
wider than the data in the columns. I want to wrap the header text in
each column so that it is as wide as the widest entry in the rest of that
column. Each column width is diferent.

If anybody knows a quick method of doing this, it would save me a lot of
time.



  #5   Report Post  
Dave Peterson
 
Posts: n/a
Default Wrap text in column headers to fit text in column

You may want to consider using alt-enter to force new lines within the cell.
Then you'll be able to break each header line where you want it.

MarkN wrote:

Hello,

I get about forty columns of data dumped into an Excel sheet every month.
The column headers at the top of the columns are usually considerably wider
than the data in the columns. I want to wrap the header text in each column
so that it is as wide as the widest entry in the rest of that column. Each
column width is diferent.

If anybody knows a quick method of doing this, it would save me a lot of time.
--
Thanks,
MarkN


--

Dave Peterson


  #6   Report Post  
Dave Peterson
 
Posts: n/a
Default Wrap text in column headers to fit text in column

You can look and just adjust.

With ActiveCell.EntireRow
MsgBox .RowHeight & " -- before"
.RowHeight = .RowHeight - 1
MsgBox .RowHeight & " -- before"
End With

But sometimes, it's a mistake to do. You could be chopping the top or bottom
line of characters.

Jim May wrote:

Neat Rowan; Is there a way to "nudge-up" the spacing
a few more characters "above the standard "autofit amt?
If so, how?
TIA,

"Rowan Drummond" wrote in message
...
Maybe with a macro. Assuming your headers are in row 1:

Sub header()
Dim eCol As Integer
Dim i As Integer
Dim head As String
eCol = Cells(1, Columns.Count).End(xlToLeft).Column
For i = 1 To eCol
With Cells(1, i)
head = .Value
.ClearContents
.EntireColumn.AutoFit
.WrapText = True
.Value = head
End With
Next i
End Sub

Hope this helps
Rowan

MarkN wrote:
Hello,

I get about forty columns of data dumped into an Excel sheet every month.
The column headers at the top of the columns are usually considerably
wider than the data in the columns. I want to wrap the header text in
each column so that it is as wide as the widest entry in the rest of that
column. Each column width is diferent.

If anybody knows a quick method of doing this, it would save me a lot of
time.


--

Dave Peterson
  #7   Report Post  
MarkN
 
Posts: n/a
Default Wrap text in column headers to fit text in column

Hello Rowan

Thank you for your reply Rowan, this comes close but I have now identified
another problem! Is there something that I can do so when the column headers
wrap to the autofit, the wrapping only occurs at breaks between words (not
anywhere within the word as I now have column headers that are difficult to
read where the width of the data in the column is only two or three
characters).

--
Thanks,
MarkN


"Rowan Drummond" wrote:

Maybe with a macro. Assuming your headers are in row 1:

Sub header()
Dim eCol As Integer
Dim i As Integer
Dim head As String
eCol = Cells(1, Columns.Count).End(xlToLeft).Column
For i = 1 To eCol
With Cells(1, i)
head = .Value
.ClearContents
.EntireColumn.AutoFit
.WrapText = True
.Value = head
End With
Next i
End Sub

Hope this helps
Rowan

MarkN wrote:
Hello,

I get about forty columns of data dumped into an Excel sheet every month.
The column headers at the top of the columns are usually considerably wider
than the data in the columns. I want to wrap the header text in each column
so that it is as wide as the widest entry in the rest of that column. Each
column width is diferent.

If anybody knows a quick method of doing this, it would save me a lot of time.


  #8   Report Post  
Rowan Drummond
 
Posts: n/a
Default Wrap text in column headers to fit text in column

Hi Mark

Try this adaption:

Sub header()
Dim eCol As Integer
Dim i As Integer
Dim head As String
Dim hdArr As Variant
Dim j As Integer
Dim hdLen As Integer
Dim tLen As Integer

eCol = Cells(1, Columns.Count).End(xlToLeft).Column
Rows(1).WrapText = False
For i = 1 To eCol
With Cells(1, i)
head = .Value
hdArr = Split(head, " ")
For j = 0 To UBound(hdArr)
tLen = Len(hdArr(j))
If tLen hdLen Then
hdLen = tLen
End If
Next j
.Value = String(hdLen, "X")
.EntireColumn.AutoFit
.WrapText = True
.Value = head
hdLen = 0
End With
Erase hdArr
Next i
End Sub

Regards
Rowan

MarkN wrote:
Hello Rowan

Thank you for your reply Rowan, this comes close but I have now identified
another problem! Is there something that I can do so when the column headers
wrap to the autofit, the wrapping only occurs at breaks between words (not
anywhere within the word as I now have column headers that are difficult to
read where the width of the data in the column is only two or three
characters).

  #9   Report Post  
MarkN
 
Posts: n/a
Default Wrap text in column headers to fit text in column

Hi Rowan,

That is exactly what I needed, you are a gentleman and a scholar.
--
Thanks,
MarkN


"Rowan Drummond" wrote:

Hi Mark

Try this adaption:

Sub header()
Dim eCol As Integer
Dim i As Integer
Dim head As String
Dim hdArr As Variant
Dim j As Integer
Dim hdLen As Integer
Dim tLen As Integer

eCol = Cells(1, Columns.Count).End(xlToLeft).Column
Rows(1).WrapText = False
For i = 1 To eCol
With Cells(1, i)
head = .Value
hdArr = Split(head, " ")
For j = 0 To UBound(hdArr)
tLen = Len(hdArr(j))
If tLen hdLen Then
hdLen = tLen
End If
Next j
.Value = String(hdLen, "X")
.EntireColumn.AutoFit
.WrapText = True
.Value = head
hdLen = 0
End With
Erase hdArr
Next i
End Sub

Regards
Rowan

MarkN wrote:
Hello Rowan

Thank you for your reply Rowan, this comes close but I have now identified
another problem! Is there something that I can do so when the column headers
wrap to the autofit, the wrapping only occurs at breaks between words (not
anywhere within the word as I now have column headers that are difficult to
read where the width of the data in the column is only two or three
characters).


  #10   Report Post  
Rowan Drummond
 
Posts: n/a
Default Wrap text in column headers to fit text in column

I should have mentioned that the split function was not available pre
excel 2000 so if you are running an older version of excel then the
solution as it is will result in an error.

Regards
Rowan

Rowan Drummond wrote:
Hi Mark

Try this adaption:

Sub header()
Dim eCol As Integer
Dim i As Integer
Dim head As String
Dim hdArr As Variant
Dim j As Integer
Dim hdLen As Integer
Dim tLen As Integer

eCol = Cells(1, Columns.Count).End(xlToLeft).Column
Rows(1).WrapText = False
For i = 1 To eCol
With Cells(1, i)
head = .Value
hdArr = Split(head, " ")
For j = 0 To UBound(hdArr)
tLen = Len(hdArr(j))
If tLen hdLen Then
hdLen = tLen
End If
Next j
.Value = String(hdLen, "X")
.EntireColumn.AutoFit
.WrapText = True
.Value = head
hdLen = 0
End With
Erase hdArr
Next i
End Sub

Regards
Rowan

MarkN wrote:

Hello Rowan

Thank you for your reply Rowan, this comes close but I have now
identified another problem! Is there something that I can do so when
the column headers wrap to the autofit, the wrapping only occurs at
breaks between words (not anywhere within the word as I now have
column headers that are difficult to read where the width of the data
in the column is only two or three characters).



  #11   Report Post  
Rowan Drummond
 
Posts: n/a
Default Wrap text in column headers to fit text in column

You're welcome.

MarkN wrote:
Hi Rowan,

That is exactly what I needed, you are a gentleman and a scholar.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count Intervals of Filtered TEXT values in Column and Return Count across a Row Sam via OfficeKB.com Excel Worksheet Functions 9 July 31st 05 03:37 AM
Arithmetical Mode of Criteria in Multiple Non-Adjacent columns Sam via OfficeKB.com Excel Worksheet Functions 4 July 14th 05 09:15 PM
row height not accounting for wrap text cwinters Excel Discussion (Misc queries) 1 July 8th 05 04:09 PM
Wrap text limits in Excel 2003 cell formatting Adelrose Excel Discussion (Misc queries) 1 April 19th 05 06:32 PM
Putting text in a column based on variable text from another colum Jacky D. Excel Discussion (Misc queries) 1 December 16th 04 06:09 PM


All times are GMT +1. The time now is 10:07 AM.

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

About Us

"It's about Microsoft Excel"