PDA

View Full Version : Solved: Deleting excess characters in a cell



Gavint
08-29-2006, 08:03 PM
I need a simple macro to check a cell and removes any text after the first 4 characters, then loops through each cell in that column until finished (no more text).

The cells are going to have some text (between 6 and 15 characters long), but only the first 4 characters are relevant, so the rest needs to be deleted)

I had a play with string lengths and looping, but I'm not having much luck getting it to work.


Thanks!

geekgirlau
08-29-2006, 08:08 PM
Do you need a macro for this? You can get the data you need with a formula: =LEFT(A1,4)

johnske
08-29-2006, 08:15 PM
With VBA...
Option Explicit

Sub TryMe()

Dim Cell As Range

For Each Cell In Range("A1", Range("A" & Rows.Count).End(xlUp).Address)
Cell = Left(Cell, 4)
Next
End Sub

Gavint
08-30-2006, 05:54 PM
Thanks guys - 2 great responses overnight!

Damn I love this site :)