How to trim text in a column with VBA - Excel
How can I trim a the text in each cell in a column?
If the syntax is like: "blabla@twitter.com (name name)" and I want to delete "@twitter.com (name name)" from all cells in the column being left with only "blabla" in th开发者_开发百科e cells.
Any ideas?
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
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.
精彩评论