Dạ em cảm ơn thầy, Nếu có thời gian xin được nhờ thầy có thể giúp em bằng code với ạ?=TRIM( SUBSTITUTE( G2,";","",LEN( G2)-LEN( SUBSTITUTE(G2,";",""))))
Code thì chỉ "bấm một phát"=TRIM( SUBSTITUTE( G2,";","",LEN( G2)-LEN( SUBSTITUTE(G2,";",""))))
Em cảm ơn thầy ạ!Sub t
const sColRef = "G"
const iRowMin = 2
const sDelim = ";"
Dim ws as worksheet, data as variant, lastRow as long, i as long, strText as string
set ws = activesheet
lastRow = ws.range(sColRef, ws.rows.count).end(xlup).row
if lastRow < iRowMin then
msgbox "Khong co du lieu!"
Exit sub
End if
data = ws.range(sColRef & iRowMin).resize(lastRow - iRowMin +1 +1).value2
lastRow = ubound(data,1) -1
for i = 1 to lastRow
strText = vba.trim$(data(i,1))
if vba.right$(strText,1) = sDelim then
mid(strText, len(strText),1) = ""
data(i,1) =vba.trim$( strText)
end if
next i
ws.range(sColRef & iRowMin).resize(lastRow).value = data
End sub
Sub delete()
Dim cell As Range
For Each cell In Range("G4:G" & Cells(Rows.Count, "G").End(xlUp).Row)
cell.Value = Split(cell.Value & "$?#", ";$?#")(0)
Next
End Sub
Em chạy code thấy báo lỗi ạ!Sub t
const sColRef = "G"
const iRowMin = 2
const sDelim = ";"
Dim ws as worksheet, data as variant, lastRow as long, i as long, strText as string
set ws = activesheet
lastRow = ws.range(sColRef, ws.rows.count).end(xlup).row
if lastRow < iRowMin then
msgbox "Khong co du lieu!"
Exit sub
End if
data = ws.range(sColRef & iRowMin).resize(lastRow - iRowMin +1 +1).value2
lastRow = ubound(data,1) -1
for i = 1 to lastRow
strText = vba.trim$(data(i,1))
if vba.right$(strText,1) = sDelim then
mid(strText, len(strText),1) = ""
data(i,1) =vba.trim$( strText)
end if
next i
ws.range(sColRef & iRowMin).resize(lastRow).value = data
End sub
em cảm ơn thầy, với những ô mà không có ký tự cần xóa ở cuối dòng thì lại tự thêm ký tự như hình khi chạy code, thầy xem giúp em ạNếu dưới vài ngàn dòng thì dùng cách này:
Nhiều hơn thì ghi vào mảng rồi dán xuống sheet nhé.PHP:Sub delete() Dim cell As Range For Each cell In Range("G4:G" & Cells(Rows.Count, "G").End(xlUp).Row) cell.Value = Split(cell.Value & "$?#", ";$?#")(0) Next End Sub
Em chạy code thấy báo lỗi ạ!
Em có sửa lại và chạy code nhưng không có tác dụng ạ!Mình viết sai. Bạn chỉnh lại thế này nhé.
lastRow = ws.range(sColRef & ws.rows.count).end(xlup).row
.Em có sửa lại và chạy code nhưng không có tác dụng ạ!
Xin được thầy xem giúp!
Sub delete()
Dim cell As Range
For Each cell In Range("G4:G" & Cells(Rows.Count, "G").End(xlUp).Row)
If Right(cell, 1) Like ";" Then cell.Value = Split(cell.Value & "$?#", ";$?#")(0)
Next
End Sub
Vâng, em cảm ơn thầyThử lại:
PHP:Sub delete() Dim cell As Range For Each cell In Range("G4:G" & Cells(Rows.Count, "G").End(xlUp).Row) If Right(cell, 1) Like ";" Then cell.Value = Split(cell.Value & "$?#", ";$?#")(0) Next End Sub
Dạ được rồi ạ! em xin cảm ơn!.
Đây bạn nhé .