EXCEL 2010:使用VBA将多个单元格拆分 [英] EXCEL 2010: Split Cells using VBA to multiple Cells

查看:139
本文介绍了EXCEL 2010:使用VBA将多个单元格拆分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的数据目前位于列($ T10)



我目前有行数据类似于:

Jane Doe(doe.jane@___.com)

JOHN DOE,SR(noemail-8858)< br>
第一个第二个DE姓surname2(email@_______.com)

第一个中间姓氏(email@_____.net)



公式获取正常名称:

  [First Surname] = IF($ C2678 = 1,(LEFT(B2684, SEARCH((,B2684)-1)),)
[名字] = IF($ C4068 = 1,(LEFT(TRIM(B4074),FIND(,TRIM(B4074)) -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 (B3894))+ 1,99)) - $)
[surname] = IF($ C4068 = 1,(TRIM(RIGHT(SUBSTITUTE(TRIM(LEFT(B4074,FIND ($ C4068 = 1,(MID(TRIM(TROL)(B4074)-1),,REPT(,99)),99))),)
[email] = IF B4074),FIND( (,TRIM(B4074))+ 1,FIND(),TRIM(B4074)) - FIND((,TRIM(B4074)) - 1)),)

结果(编辑):

  |贾恩·多| jane |中间| Doe | doe.jane@____.com | 
|第一姓|第一|中间|姓| noemail-8858 |

我查看了 TRIM SPLIT 函数,但是我无法找到一个分配给变量的方法(,())在一个单元格中。



我已经使用过:

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



http://www.exceltrick.c om / formula_macros / vba-split-function /



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



非常感谢提前。



这是2014年我以前的查询的扩展,我可以得到公式。

Excel 2010在IF函数中搜索文本 - 单独的单元格数据

解决方案

不完全分析您的公式正在做什么我假设你很高兴他们的工作正确吗?)然后我看不出为什么你不能直接转换它们全部?



开始点:

  = IF($ C3888 = 1,(IF(LEN(TRIM(B3894)) -  LEN(SUBSTITUTE(B3894, ),3,,LEFT(MID(TRIM(B3894),FIND(,TRIM(B3894))+ 1,99),FIND(,MID(TRIM(B3894) (,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



,)

我想你有几个太多的中尺寸和左边比你需要。这是我如何解释在修剪值的第一个和第二个空格之间获得这个词...是对的吗?



VBA-afied: p>

 函数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

如果rgName.Offset(-6,1).Value = 1 Then'This给出B3894中的C3888
stTrimmed = Trim(rgName.Value)
intTrimmed = Len(stTrimmed)
intNoSpace = Len(Replace(rgName.Value, ))

如果intTrimmed - intNoSpace<> 3然后
GetMiddleName =
退出函数
Else
intFirstSpace = InStr(1,stTrimmed,)
intSecondSpace = InStr(intFirstSpace + 1,stTrimmed, )

GetMiddleName = Mid(stTrimmed,intFirstSpace + 1,intSecondSpace - (intFirstSpace + 1))
退出函数
如果
Else
GetMiddleName =
结束如果
结束函数

希望能让你开始与其他公式的一些想法... PS VBA中的rept公式=string(我不知道有一个rept公式!尼斯!)



给我这些结果:

 Jane Doe(doe.jane@___.com)=(失败len-nospaces<> 3检查)
JOHN DOE,SR(noemail-8858)=DOE(可能要添加一个Replace(,...))
first second DE surname surname2(email@_______.com)=(< 3检查失败)
第一中间姓(email@_____.net)=中间工程扫荡?


I am looking for some help converting my formulas to VBA code.

My data is currently in Column ($T10)

I currently have rows of data similar to:
Jane Doe (doe.jane@___.com)
JOHN DOE, SR (noemail-8858)
first second DE surname surname2 (email@_______.com)
first middle surname (email@_____.net)

Formulas to get the 'normal' names:

[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)),"")  

Results (edited):

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

I've looked at both TRIM and SPLIT functions, however I haven't been able to find a way to split given the variables (, ( )) in the one cell.

I've used:
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

http://www.exceltrick.com/formulas_macros/vba-split-function/

They aren't really piecing together what I need. I can get some basics, but not the more complex formulas converted to VBA.

Many thanks in advance.

This is an extension of my previous enquiry in 2014, where I was able to get the formulas.
Excel 2010 search for text in IF function - separate cell data

解决方案

Short of analysing exactly what your formulas are currently doing (i assume you're happy with how they work right?) then I can't see why you can't directly convert them all?

Start point:

=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))),"")

Formatted more:

=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
         )
       )
      )
   ,"")

I think you've got a few too many Mids and Lefts than you need. This is how I've interpreted "Get the word between the first and second spaces of the trimmed value"... Is that right?

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

Hopefully that gets you started with some ideas for the other formulas... PS the "rept" formula = "string" in VBA (I didn't know there was a rept formula! Nice one!)

That gives me these results:

"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?

这篇关于EXCEL 2010:使用VBA将多个单元格拆分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆