Nhờ chuyển sang hàm sử dụng trong excel!!!

Liên hệ QC

nguyenanhdung8111982

Thành viên hoạt động
Tham gia
1/11/19
Bài viết
120
Được thích
33
Giới tính
Nam
em có tìm thấy đoạn code như dưới tách chuỗi những ô có waraptext. Nhờ anh chị chuyển code từ sub sang function sử dụng trong excel!!!
Hoặc sửa code khi chạy chọn theo range của cột thay vì click từng ô.
Mã:
Sub splitText()
'splits Text active cell using ALT+10 char as separator
Dim splitVals As Variant
Dim totalVals As Long
'Range(ActiveCell, ActiveCell.End(xlDown)).Select
splitVals = Split(ActiveCell.Value, Chr(10))
totalVals = UBound(splitVals)
Range(Cells(ActiveCell.Row, ActiveCell.Column + 1), Cells(ActiveCell.Row, ActiveCell.Column + 1 + totalVals)).Value = splitVals

End Sub

1618372822369.png
 
Thử công thức này:

B1=TRIM(MID(SUBSTITUTE($A1,CHAR(10),REPT(" ",100)),1+(COLUMN(A1)-1)*99,99))
 
em có tìm thấy đoạn code như dưới tách chuỗi những ô có waraptext. Nhờ anh chị chuyển code từ sub sang function sử dụng trong excel!!!
Hoặc sửa code khi chạy chọn theo range của cột thay vì click từng ô.
Mã:
Sub splitText()
'splits Text active cell using ALT+10 char as separator
Dim splitVals As Variant
Dim totalVals As Long
'Range(ActiveCell, ActiveCell.End(xlDown)).Select
splitVals = Split(ActiveCell.Value, Chr(10))
totalVals = UBound(splitVals)
Range(Cells(ActiveCell.Row, ActiveCell.Column + 1), Cells(ActiveCell.Row, ActiveCell.Column + 1 + totalVals)).Value = splitVals

End Sub
Thử code sau:
Mã:
Function splitText(txt As String, ViTri As Long) As String
Dim Arr As Variant
Arr = Split(txt, ChrW(10))
If ViTri - 1 <= UBound(Arr) Then splitText = Arr(ViTri - 1)
End Function
Trong B1, nhập:

=splitText($A1,COLUMN(A1))
 
Thử công thức này:

B1=TRIM(MID(SUBSTITUTE($A1,CHAR(10),REPT(" ",100)),1+(COLUMN(A1)-1)*99,99))
Công thức ok!!! cám ơn bạn
Bài đã được tự động gộp:

Thử code sau:
Mã:
Function splitText(txt As String, ViTri As Long) As String
Dim Arr As Variant
Arr = Split(txt, ChrW(10))
If ViTri - 1 <= UBound(Arr) Then splitText = Arr(ViTri - 1)
End Function
Trong B1, nhập:

=splitText($A1,COLUMN(A1))
Cám ơn bạn!!! hàm chạy ok!!!
 
Web KT
Back
Top Bottom