Sayın arkadaşlar ekteki örnek dosyanın içerisinde bulunan aşağıdaki makroda sayfa1 a5 satırındaki hücreleri birleştirdiğimde sayda2 de a1 hücresine veri girdiğim zaman veya verileri sildiğim zaman hata mesajı alıyorum yardımcı olurmusunz?
Public Sub AutoFitMergedCellRowHeight()
Sheets("Sayfa1").Rows("5:5").EntireRow.AutoFit
Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
Dim CurrCell As Range
Dim ActiveCellWidth As Single, PossNewRowHeight As Single
For Each i In Sayfa1.UsedRange
If i.MergeCells Then
i.Select
With ActiveCell.MergeArea
If .Rows.Count = 1 And .WrapText = True Then
CurrentRowHeight = .RowHeight
ActiveCellWidth = ActiveCell.ColumnWidth
For Each CurrCell In Selection
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)
End If
End With
Exit For
End If
Next i
End Sub
Public Sub AutoFitMergedCellRowHeight()
Sheets("Sayfa1").Rows("5:5").EntireRow.AutoFit
Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
Dim CurrCell As Range
Dim ActiveCellWidth As Single, PossNewRowHeight As Single
For Each i In Sayfa1.UsedRange
If i.MergeCells Then
i.Select
With ActiveCell.MergeArea
If .Rows.Count = 1 And .WrapText = True Then
CurrentRowHeight = .RowHeight
ActiveCellWidth = ActiveCell.ColumnWidth
For Each CurrCell In Selection
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)
End If
End With
Exit For
End If
Next i
End Sub
