Word wrap macro deletes formula

D

David

I created a macro to wrap text on a protected worksheet
in which each cell contains a formula importing text from
another worksheet. The cells are locked and formulas
hidden but when I run the macro, it wraps the text and
deletes the formula> how can I stop it doing this? The
macro is as follows:
Sub Wordwrap()
'
' Wordwrap Macro
' Macro recorded 01/10/2004
'
' Keyboard Shortcut: Ctrl+w
'
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
End Sub

David
 
S

SeaparkJohn

I've taken the code below and dropped it into a sample spreadhseet, which
imports from another page -- it works fine for me. Have you tried reusing
all of the elements on a new workbook? Sometimes VB tends to do things it
shouldn't if a workbook has been used repeatedly.

But the code below is fine

Hope this helps
 
F

Frank Kabel

Hi
just tested your macro and it does NOT delete the formulas in my test
case?. What formula ahve you used?
 
D

Dave Peterson

And I'd watch out for that shortcut key combination.

ctrl-w usually closes the activewindow (maybe with a prompt).

You may be surprised if your hit ctrl-w sometime and things close.

I might use
ctrl-W
(shift-w)
 
Top