thanhnam0119
Thành viên hoạt động



- Tham gia
- 5/10/07
- Bài viết
- 152
- Được thích
- 4
Sub ReplaceHyphenWithCommaSpaceInColumn()
Dim ws As Worksheet
Dim lastRow As Long
Dim columnRange As Range
Dim cell As Range
Set ws = ThisWorkbook.Sheets("XLxa")
lastRow = ws.Cells(ws.Rows.Count, "F").End(xlUp).Row
Set columnRange = ws.Range("F3:F" & lastRow)
Dim tempData As Variant
tempData = columnRange.Value
For Each cell In columnRange
cell.Value = Replace(cell.Value, " - ", ", ")
cell.Value = Replace(cell.Value, "-", ", ")
cell.Value = Replace(cell.Value, "- ", ", ")
cell.Value = Replace(cell.Value, " -", ", ")
Next cell
End Sub
em có code như này nhưng khi chạy dữ liệu thấy lâu không nhanh như sử dụng Repalce trong excel nhờ anh chị giúp xử lý chạy nhanh với dữ liệu lớn (hơn trăm nghìn bản ghi)
Dim ws As Worksheet
Dim lastRow As Long
Dim columnRange As Range
Dim cell As Range
Set ws = ThisWorkbook.Sheets("XLxa")
lastRow = ws.Cells(ws.Rows.Count, "F").End(xlUp).Row
Set columnRange = ws.Range("F3:F" & lastRow)
Dim tempData As Variant
tempData = columnRange.Value
For Each cell In columnRange
cell.Value = Replace(cell.Value, " - ", ", ")
cell.Value = Replace(cell.Value, "-", ", ")
cell.Value = Replace(cell.Value, "- ", ", ")
cell.Value = Replace(cell.Value, " -", ", ")
Next cell
End Sub
em có code như này nhưng khi chạy dữ liệu thấy lâu không nhanh như sử dụng Repalce trong excel nhờ anh chị giúp xử lý chạy nhanh với dữ liệu lớn (hơn trăm nghìn bản ghi)