之后在左侧复制并粘贴文本

之后在左侧复制并粘贴文本

本文介绍了Excel VBA-在CHAR(10)之后在左侧复制并粘贴文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果满足以下条件:

A1 =fsfsdfsdfs

A1=fsfsdfsdfs

qewqeqewqe

qewqeqewqe

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

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

然后B1将显示"qewqeqewqe".

Then B1 would display "qewqeqewqe".

这仅可直接用于excel单元格.鉴于上述以下条件,我将如何编写这一行代码?

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

类似下面的内容?

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

我不会问我是否没有搜索它.我一直发现的是如何在excel文件而不是VBA中执行此操作.任何帮助将不胜感激.谢谢!

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

推荐答案

这应该做到

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

检查一下, http://www.xlorate.com/vba-examples.html#Split%20Cells

这篇关于Excel VBA-在CHAR(10)之后在左侧复制并粘贴文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 00:34