修剪以逗号开始的string – Excel
我有一个excel表,其中Employee的数据为Last Name,First Name。 下面是一个例子。 (这些值在一个单元格中)
Flynn, Jeremy Early, Allison Epstein, David Newman, Joanna Biord, Brooke
我需要修剪数据,以便我只需要没有任何尾随空格或逗号的名字。
OutPut示例应该是:
Jeremy Allison David Joanna Brooke
我怎样才能写一个公式或macros,将处理整个5000张以上的logging。
作为使用REPLACE函数右边使用的列中的公式,
=REPLACE(A1, IFERROR(FIND(",", A1), LEN(A1)), LEN(A1), TEXT(,))
作为使用Range.Replace方法的VBA子程序,
Sub firstOnly_bySel() With Selection .Replace what:=",*", replacement:=vbNullString, lookat:=xlPart 'selection.replace( End With End Sub
select一个或多个单元格并从macros对话框([alt] + [F8])运行子
公式,在一个空栏里放:
=TRIM(MID(A1,Find(",",A1)+1,LEN(A1)))
A1是您列表中的第一个单元格。 然后复制整个列表。
如果你想vba,这将几乎立即做到这一点:
Sub firstName() Dim rng As Range With ActiveWorkbook.ActiveSheet 'Change the Second Criterion in Each .Cells() to the column number of your data. Set rng = .Range(.Cells(1, 1), Cells(.Rows.Count, 1).End(xlUp)) 'Change the Offset value to the number of columns to offset the answer. rng.Offset(, 1).Value = .Evaluate("Index(TRIM(MID(" & rng.Address & ",Find("",""," & rng.Address & ")+1,LEN(" & rng.Address & "))),)") End With End Sub
它假定你的数据在列A中,并将它放在列B中
只要做简单的查找和replace。 find“,*”并将“replace为空白”。