Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
198 views
in Technique[技术] by (71.8m points)

vba - How to delete some text in-between a string in a cell in excel

I have some company addresses in an excel - here is how one of the cells look like. The number of company addresses in any cell varies.

abc
United Kingdom
Main Phone: 1234567
Main Fax: 63273818
Other Phone: 53177188

dfr
China
Main Phone: 2345671
Main Fax: 632738188

rtg
United States
Main Phone: 2434571
Main Fax: 3278188
Other Phone: 31771988

What I want as a outcome is 

abc
United Kingdom

dfr
China

rtg
United States

I have researched for this; however, could not find anything. I am trying to find a way to get the position of "Main" and the empty line and then delete the text in between. I tried with CHAR(10) & CHAR(13)..but those did not work. Any help in this regard would be welcome. Many thanks.

P.S>> If anyone can suggest any VBA code to do work, that would be also useful. Many thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use this Function:

Function remo(txt As String) As String

    txt1 = Split(txt, Chr(10) & Chr(10))

    For i = LBound(txt1) To UBound(txt1)

        remo = remo & Left(txt1(i), InStr(1, txt1(i), "Main") - 1) & Chr(10) & Chr(10)
        Debug.Print txt2

    Next

End Function

enter image description here

Here you will find how to add a Custom Function In Excel


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...