I am new to the world of VBA and am having a problem.
I want to autofit rows that have merged cells in them.
I did take some code from another thread on the forum.
See below, my appologies for not referenceing the author I simply can not find where I got it from.
Also, I chose
this one because it does it as you are in the cell rather than afterwards.
I receive an error stating:
"Unable to set the ColumnWidth property of the range class"
Does anyone have an Idea how to fix it?
Thank you, JIM
Private Sub Worksheet_Change(ByVal Target As Range)
Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
Dim CurrCell As Range
Dim ActiveCellWidth As Single, PossNewRowHeight As Single
If ActiveCell.MergeCells Then
If .Rows.Count = 1 And .WrapText = True Then
Application.ScreenUpdating = False
CurrentRowHeight = .RowHeight
ActiveCellWidth = ActiveCell.ColumnWidth
For Each CurrCell In Selection
MergedCellRgWidth = CurrCell.ColumnWidth + MergedCellRgWidth
.MergeCells = False
.Cells(1).ColumnWidth = MergedCellRgWidth
PossNewRowHeight = .RowHeight
.Cells(1).ColumnWidth = ActiveCellWidth
.MergeCells = True
.RowHeight = IIf(CurrentRowHeight > PossNewRowHeight, _