View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
B Lynn B B Lynn B is offline
external usenet poster
 
Posts: 131
Default Need help with Trim function

replace line Temp = Target.Formula with Temp = Trim(Target.Formula)

Might be worth noting that this will not leave any actually formulas on your
sheet should you try to put them in. If I were doing this, I might be
inclined to put a test on the cell contents to see if the first character is
"=", then skip the action if true.

"Bob" wrote:

The following block of code strips away any formatting from copied text
before it is pasted.

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Dim Temp As Variant
Temp = Target.Formula
On Error GoTo endit
With Application
.EnableEvents = False
.Undo
Target.Formula = Temp
.EnableEvents = True
End With
endit:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

I would like to ensure that any extra spaces in the copied text is also
removed before the text is pasted.

Can someone show me how to incorporate the Trim function in the code above.

Thanks,
Bob