Excel VBA- Copy and paste text on left after CHAR(10)

时光怂恿深爱的人放手 提交于 2020-01-15 22:27:13

问题


If the following conditions:

A1= fsfsdfsdfs

qewqeqewqe

B1= RIGHT(A1,FIND(CHAR(10),A1&" "))

Then B1 would display "qewqeqewqe".

This works only directly into an excel cell. How would I write this line of code given the following conditions above?

Something like the below?

Worksheets("sheet1").Cells(1,2).value= left(find(CHR(10), Worksheets("sheet1").Cells(1,1),&""))?????

I would not be asking if I had not searched for it. All I keep finding is how to do it in an excel file and not the VBA. Any help would be greatly appreciated. Thanks!

Sub test()

Dim txt As String
Dim fullname As String

txt = Worksheets("Sheet1").Cells(1, 1).Value
fullname = Split(txt, Chr(10))

Worksheets("Sheet1").Cells(1, 2).Value = fullname

End Sub

回答1:


This should do it

Sub Button1_Click()
    Dim rng As Range
    Dim i As Integer
    Dim Orig As Variant
    Dim txt As String

    Set rng = Range("A1")

    txt = rng.Value

    Orig = Split(txt, Chr(10))

    For i = 0 To UBound(Orig)
        Cells(1, i + 1) = Orig(i)
    Next i

End Sub

Check this out, http://www.xlorate.com/vba-examples.html#Split%20Cells



来源:https://stackoverflow.com/questions/30336434/excel-vba-copy-and-paste-text-on-left-after-char10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!