Macro deletes formula

P

Pennington

I have created a macro to restore the row height in a protected worksheet
when text in a cell of the parent worksheet is deleted but when I run the
macro it deletes the formula in the cell. The macro is:
Sub Autoheight()
'
' Autoheight Macro
' Macro recorded 12/10/2004
' Keyboard Shortcut: Ctrl D
' Dim myCell As Range

For Each myCell In Selection
myCell.Value = AutoFit
Next myCell
End Sub
What changes do I need to make to the macro prevent the formula in the cell
being deleted?
 
P

Pennington

Don
Thanks. Tried this but got runtime error 1004
Autofit method of Range class failed

What other solution might there be?
 
G

Gord Dibben

I don't believe cells have an Autofit Property.

Try Selection.Rows.Autofit

Sub Autoheight()
'
' Autoheight Macro
' Macro recorded 12/10/2004
' Keyboard Shortcut: Ctrl D
' Dim myCell As Range

Selection.Rows.AutoFit
End Sub

Gord Dibben Excel MVP
 
Top