VBA to TRIM data <--Rookie here :o)
On Jan 10, 2:29*pm, JP wrote:
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- Hide quoted text -
- Show quoted text -
Thanks for the assistance. Another question please...some of the
cells in this range start with a 0, ie 0345681. After trying the
suggested code, it is removing the leading zeros. How can these cells
be treated as text so the zero stays in tact?
Regards,
Dan
|