Các Thầy cho em hỏi em muốn tìm lần lượt các giá trị trong ô ở dòng 1 thì ntn? (1 người xem)

Người dùng đang xem chủ đề này

Lequocvan

Thành viên thường trực
Tham gia
21/8/07
Bài viết
365
Được thích
129
Donate (Paypal)
Donate
Donate (Momo)
Donate
Giới tính
Nam
Nghề nghiệp
Agribank
Các Thầy giúp em cách giải quyết nhanh và tốt hơn: em muốn tìm lần lượt các giá trị trong từng ô ở dòng 1, ví dụ nếu tìm thấy SoDienThoai thì thay bằng Tel1, nếu tìm thấy DiaChi thì thay bằng addr, ... em có khoảng 93 cột ở dòng 1. nếu làm thủ công thì em làm như bên dưới, nhưng em thấy chưa hay ở chỗ phải gõ thủ công nhiều ah. Các Thầy giúp em nhé!
sub chaythu()
Cells.Replace What:="SoDienThoai", Replacement:="Tel1", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:="Xa", Replacement:="TenXa", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:="Phuong", Replacement:="TenPhuong", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
'..............
end sub
 
Lần chỉnh sửa cuối:
Các Thầy giúp em cách giải quyết nhanh và tốt hơn: em muốn tìm lần lượt các giá trị trong từng ô ở dòng 1, ví dụ nếu tìm thấy SoDienThoai thì thay bằng Tel1, nếu tìm thấy DiaChi thì thay bằng addr, ... em có khoảng 93 cột ở dòng 1. nếu làm thủ công thì em làm như bên dưới, nhưng em thấy chưa hay ở chỗ phải gõ thủ công nhiều ah. Các Thầy giúp em nhé!
sub chaythu()
Cells.Replace What:="SoDienThoai", Replacement:="Tel1", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:="Xa", Replacement:="TenXa", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:="Phuong", Replacement:="TenPhuong", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
'..............
end sub
Thử thế này
PHP:
Sub chaythu()
Dim i, ChuoiGoc(), ChuoiMoi()
ChuoiGoc = Array("SoDienThoai", "Xa", "Phuong")
ChuoiMoi = Array("Tel1", "TenXa", "TenPhuong")
For i = LBound(ChuoiGoc) To UBound(ChuoiGoc)
   Cells.Replace ChuoiGoc(i), ChuoiMoi(i)
Next
End Sub
Có thể tạo sẵn bảng dò bên ngoài sẽ tiện hơn
 
Upvote 0

Bài viết mới nhất

Back
Top Bottom