tags:

views:

51

answers:

2

How can I trim a the text in each cell in a column?

If the syntax is like: "[email protected] (name name)" and I want to delete "@twitter.com (name name)" from all cells in the column being left with only "blabla" in the cells.

Any ideas?

+1  A: 

Found a solution:

Dim cellHolder As String
For Each cell In Range("A1:A10")
    cellHolder = cell.Value
    cellHolder = Left(cellHolder, InStr(cellHolder, "@") - 1)
    cell.Value = cellHolder
Next cell
Noop
+1  A: 

You do not need to use VBA to achive this in Excel.

Assuming the your text is in column A, the following formula in an adjacent column for each row will do what you need for your example.

=LEFT(A1,FIND("@",A1)-1)

You may need to elaborate this depending on the input data to account for cases where there is no @ characters in the text.

vzczc
I need to use vba because the data in the cells regulary update. and the updated data needs to be trimmed. Is there any easier way to do it? Edit: and right now there is always an @ in the text. But how can it be modified so that if there's no @ in the text it just ignores is?
Noop