How to trim text in a column with VBA - Excel

2019-09-12 04:00发布

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 the cells.

Any ideas?

标签: excel vba
2条回答
冷血范
2楼-- · 2019-09-12 04:47

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
查看更多
趁早两清
3楼-- · 2019-09-12 05:07

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.

查看更多
登录 后发表回答