vba如何提取单元格内每一行内容或如何获取单元格换行字符

2024-11-18 16:46:30
推荐回答(3个)
回答1:

步骤如下:

1.将A1按换行符分开到B之后的列中:

2.alt+F11,输入如下代码:

3.F5运行代码,结果如下:

回答2:

请测试下面的代码,思路是先将A列的内容连接在一起,然后用split根据改行拆分成各行写入B列。
Sub 改行拆分()
Dim str As String
Dim i As Integer, j As Integer, k As Integer, ar, arr
For i = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
If Len(Cells(i, 1)) > 0 Then
str = Cells(i, 1).Text & Chr(10) & str
End If
Next i

ar = Split(str, Chr(10))
ReDim arr(1 To UBound(ar) + 1, 1 To 1)
For i = 0 To UBound(ar)
k = k + 1
arr(k, 1) = ar(i)
Next
With Cells(1, 2)
.EntireColumn.NumberFormatLocal = "@"
.Resize(k) = arr
End With
End Sub

回答3:

splitdata = Split(Range("G3").Value, Chr(10)) 用 split 来提取字符串