Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Compare textwidth with cellwidth in Excel?

Hello Jim,

Excellent macro.
I'm wondering if there's a way of doing this in multiple rows at once. Is this possible?

JC
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Compare textwidth with cellwidth in Excel?

I found this code and made improvement so it can support multiple cells selection. It's little bit tricky to deal with vertical oriented text but this code support it as well (small correction is required to switch off text wrapping in case of vertical text orientation, but I omit to do it - no more time). Code checks user selection and does not support entire rows our columns selection although it can work with it (just remove checking code). Thanks guys for starting code and my code version is the following:

Sub AutoFitMergedCellRowHeight()
Dim cell As Object
Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
Dim CurrCell As Range
Dim PrevMerge As Range
Dim ActiveCellWidth As Single, PossNewRowHeight As Single
Dim FirstCell As Boolean
If Selection.Address = "$1:$1048576" Then
MsgBox ("This macro procedure for RowAutofit does not support entire rows or columns selection")
Exit Sub
End If
If Selection.Row 0 And Selection.count = Columns.count Then
MsgBox ("This macro procedure for RowAutofit does not support entire rows or columns selection")
Exit Sub
End If
If Selection.Column 0 And Selection.count = Rows.count Then
MsgBox ("This macro procedure for RowAutofit does not support entire rows or columns selection")
Exit Sub
End If
FirstCell = True
Set PrevMerge = Selection.Cells(1).MergeArea
For Each cell In Selection
If cell.MergeArea.Address < PrevMerge.Address Or FirstCell Then
With cell.MergeArea
If .Rows.count = 1 And .WrapText = True Then
Application.ScreenUpdating = False
CurrentRowHeight = .RowHeight
ActiveCellWidth = cell.ColumnWidth
For Each CurrCell In cell.MergeArea
CurrCell.Orientation = cell.MergeArea.Cells(1).Orientation
MergedCellRgWidth = CurrCell.ColumnWidth + MergedCellRgWidth
Next
.MergeCells = False
.Cells(1).ColumnWidth = MergedCellRgWidth
.EntireRow.AutoFit
PossNewRowHeight = .RowHeight
.Cells(1).ColumnWidth = ActiveCellWidth
.MergeCells = True
.RowHeight = IIf(CurrentRowHeight PossNewRowHeight, _
CurrentRowHeight, PossNewRowHeight)
CurrentRowHeight = 0
ActiveCellWidth = 0
MergedCellRgWidth = 0
PossNewRowHeight = 0
End If
End With
End If
Set PrevMerge = cell.MergeArea
Application.ScreenUpdating = True
FirstCell = False
Next cell
End Sub
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
Excel: Compare Two Worksheets Myrna Rodriguez[_4_] Excel Programming 2 December 22nd 06 05:33 PM
Excel: Compare Two Worksheets Myrna Rodriguez[_4_] Excel Programming 0 December 22nd 06 04:47 PM
How do I compare cells and if FALSE compare to next cell in EXCEL Cindie Excel Worksheet Functions 0 March 24th 06 05:29 PM
Can Excel compare 4-ABC-SS to 4 ABC-SS and see them as the same Phil Excel Worksheet Functions 1 May 5th 05 08:42 AM
compare data from one column with another and compare result to yet another Matt Williamson[_3_] Excel Programming 1 September 25th 03 08:54 PM


All times are GMT +1. The time now is 01:19 PM.

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"