EXCEL 2010:使用VBA将多个单元拆分成多个单元格

我正在寻找一些帮助转换我的公式到VBA代码。

我的数据目前在列($ T10)

我目前有数据的行类似于:
Jane Doe(doe.jane@___.com)
JOHN DOE,SR(noemail-8858)
第一秒钟姓氏姓(email@_______.com)
第一中间姓(email@_____.net)

获得“正常”名字的公式:

[First Surname] =IF($C2678=1,(LEFT(B2684,SEARCH("(",B2684)-1)),"") [first name] =IF($C4068=1,(LEFT(TRIM(B4074),FIND(" ",TRIM(B4074))-1)),"") [middle name] =IF($C3888=1,(IF(LEN(TRIM(B3894))-LEN(SUBSTITUTE(B3894," ",""))<>3,"",LEFT(MID(TRIM(B3894),FIND(" ",TRIM(B3894))+1,99),FIND(" ",MID(TRIM(B3894),FIND(" ",TRIM(B3894))+1,99))-1))),"") [surname] =IF($C4068=1,(TRIM(RIGHT(SUBSTITUTE(TRIM(LEFT(B4074,FIND("(",B4074)-1))," ",REPT(" ",99)),99))),"") [email] =IF($C4068=1,(MID(TRIM(B4074),FIND("(",TRIM(B4074))+1,FIND(")",TRIM(B4074))-FIND("(",TRIM(B4074))-1)),"") 

结果(编辑):

 | jane Doe | jane | middle | Doe | doe.jane@____.com | | first surname | first | middle | Surname | noemail-8858 | 

我已经看了两个TRIMSPLIT函数,但是我一直没能find一个方法来分割给定的variables( , ( ) )在一个单元格中。

我用过:
http://www.homeandlearn.org/left_and_right_functions.html

http://www.globaliconnect.com/excel/index.php?option=com_content&view=article&id=269:excel-vba-string-functions-left-right-mid-len-replace-instr-instrrev&catid=79&Itemid=475

VBA Split Function – How to Use

他们并没有把我需要的东西拼凑在一起。 我可以得到一些基本知识,但不是更复杂的公式转换为VBA。

提前谢谢了。

这是我之前在2014年的调查的延伸,在那里我能够得到公式。
Excel 2010在IF函数中search文本 – 单独的单元格数据

没有正确分析你的公式正在做什么(我假设你对他们的工作方式感到满意?),那么我看不出为什么你不能直接把它们全部转换?

起点:

 =IF($C3888=1,(IF(LEN(TRIM(B3894))-LEN(SUBSTITUTE(B3894," ",""))<>3,"",LEFT(MID(TRIM(B3894),FIND(" ",TRIM(B3894))+1,99),FIND(" ",MID(TRIM(B3894),FIND(" ",TRIM(B3894))+1,99))-1))),"") 

格式化更多:

 =IF($C3888=1, (IF(LEN(TRIM(B3894))-LEN(SUBSTITUTE(B3894," ","")) <>3, "", LEFT( MID( TRIM(B3894), FIND( " ", TRIM(B3894) ) +1, 99 ), FIND( " ", MID( TRIM(B3894), FIND( " ", TRIM(B3894) )+1, 99 ) )-1 ) ) ) ,"") 

我觉得你有几个Mids和Lefts比你需要的多。 这是我的解释“得到修剪值的第一个和第二个空间之间的词”…是这样吗?

VBA-afied:

 Function GetMiddleName(rgName As Range) As String Dim intTrimmed As Integer Dim intNoSpace As Integer Dim stTrimmed As String Dim intFirstSpace As Integer Dim intSecondSpace As Integer If rgName.Offset(-6, 1).Value = 1 Then ' This gives the "C3888" from the "B3894" stTrimmed = Trim(rgName.Value) intTrimmed = Len(stTrimmed) intNoSpace = Len(Replace(rgName.Value, " ", "")) If intTrimmed - intNoSpace <> 3 Then GetMiddleName = "" Exit Function Else intFirstSpace = InStr(1, stTrimmed, " ") intSecondSpace = InStr(intFirstSpace + 1, stTrimmed, " ") GetMiddleName = Mid(stTrimmed, intFirstSpace + 1, intSecondSpace - (intFirstSpace + 1)) Exit Function End If Else GetMiddleName = "" End If End Function 

希望能让你开始对其他公式的一些想法… PS VBA中的“rept”公式=“string”(我不知道有一个rept公式!不错!

这给了我这些结果:

 "Jane Doe (doe.jane@___.com)" = "" (fails the "len - nospaces <> 3" check) "JOHN DOE, SR (noemail-8858)" = "DOE," (might wanna add a Replace(","...) ) "first second DE surname surname2 (email@_______.com)" = "" (fails the "<>3" check) "first middle surname (email@_____.net)" = "middle" Works Swimingly?