View Single Post
  #4   Report Post  
Colin Hayes
 
Posts: n/a
Default

In article , Bob Phillips
writes
Not a formula, but you can do it with event code


Hi

Thanks for that. I really do need this to be a piece of code that I can
embed into an existing macro. Is that possible? The range of cells
affected would be A1 to A60000.

I did try and put this into the View Code area under the tab , but had
no joy I'm afraid.


Best Wishes

Drno



Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("A1:H10")) Is Nothing Then
With Target
If Len(.Value) 45 Then
.Value = Left(.Value, 45)
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.