Macro deletes formula

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
Don
Thanks. Tried this but got runtime error 1004
Autofit method of Range class failed

What other solution might there be?
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top