View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
JP[_4_] JP[_4_] is offline
external usenet poster
 
Posts: 897
Default VBA to TRIM data <--Rookie here :o)

Noted. Thank you!

--JP

On Jan 10, 5:14*pm, "Chip Pearson" wrote:

For Each cell In rng
* cell = Trim(cell)
*Next cell


You need to be very careful with that code because it can wipe out formulas,
replacing a formula with a value. *Also, it would be good practice to turn
off events:

On Error GoTo ErrH:
Application.EnableEvents = False
For Each cell In rng
* * If cell.HasFormula = False Then
* * * * cell = *Trim(cell)
* * End If
Next cell
ErrH:
Application.EnableEvents = True