Hi all,
I am trying to set up a function that will check if cell value overflows and change format to xlFill if so. But it returns "Object required" in Sub, it doesn't even move to the function itself
The parameter of this function is Range, but it seems like
l is causing an error as this parameter. Any ideas what can go wrong?
I am trying to set up a function that will check if cell value overflows and change format to xlFill if so. But it returns "Object required" in Sub, it doesn't even move to the function itself
The parameter of this function is Range, but it seems like
VBA Code:
ActiveCell
VBA Code:
Sub TestFillFunction()
FillCell (ActiveCell)
End Sub
VBA Code:
Function FillCell(ActCel As Range)
Dim celBeforeAutoFitSize As Double
Dim celAfterAutoFitSize As Double
celBeforeAutoFitSize = ActCel.ColumnWidth
ActCel.Columns.AutoFit
celAfterAutoFitSize = ActCel.ColumnWidth
If celAfterAutoFitSize > celBeforeAutoFitSize Then
ActCel.ColumnWidth = celBeforeAutoFitSize
ActCel.HorizontalAlignment = xlFill
Else
ActCel.ColumnWidth = celBeforeAutoFitSize
End If
End Function
Last edited: