Xóa nhiều vùng dữ liệu khác nhau trong nhiều sheets

Liên hệ QC

Uyennamph

Thành viên mới
Tham gia
31/5/20
Bài viết
21
Được thích
0
Xin chào moi người. Em muốn xóa các vùng dữ liệu khác nhau tại nhiều sheets thì dùng vba viết code như thế nào ạ? Mọi người trợ giúp em với. Em xin chân thành cảm ơn mọi người ạ. Ví dụ như xóa vùng ("A5:G100") tại sheet1 + vùng ("B10:F18") tại sheet2 + vùng ("D6:K25") tai sheet5 ạ
 
Xin chào moi người. Em muốn xóa các vùng dữ liệu khác nhau tại nhiều sheets thì dùng vba viết code như thế nào ạ? Mọi người trợ giúp em với. Em xin chân thành cảm ơn mọi người ạ. Ví dụ như xóa vùng ("A5:G100") tại sheet1 + vùng ("B10:F18") tại sheet2 + vùng ("D6:K25") tai sheet5 ạ
Thì dùng code sau:
Mã:
Sheets("sheet1").Range("A5:G100").ClearContents
Sheets("sheet2").Range("B10:F18").ClearContents
Sheets("sheet5").Range("D6:K25").ClearContents
 
Upvote 0
' 1. dùng hàm evaluate
cc = [ { "sheet1", "A5:G100"; "sheet2", "B10:F18"; "sheet3", "D6:K25" } ]
For i = 1 to ubound(cc)
Sheets(cc(1)).Range(cc(2)).ClearContents
Next i

' 2. dùng hàm Array
cc = Array( Array("sheet1", "A5:G100"), Array("sheet2", "B10:F18"), Array("sheet3", "D6:K25") )
For i = 0 to ubound(cc)
Sheets(cc(i)(0)).Range(cc(i)(1)).ClearContents
Next i

' 3. dùng hàm Split
For each cc in Split("sheet1!A5:G100, sheet2!B10:F18, sheet3!D6:K25", ", ")
Sheets(Split(cc, "!")(0)).Range(Split(cc, "!")(1)).ClearContents
Next sh
 
Upvote 0
' 1. dùng hàm evaluate
cc = [ { "sheet1", "A5:G100"; "sheet2", "B10:F18"; "sheet3", "D6:K25" } ]
For i = 1 to ubound(cc)
Sheets(cc(1)).Range(cc(2)).ClearContents
Next i

' 2. dùng hàm Array
cc = Array( Array("sheet1", "A5:G100"), Array("sheet2", "B10:F18"), Array("sheet3", "D6:K25") )
For i = 0 to ubound(cc)
Sheets(cc(i)(0)).Range(cc(i)(1)).ClearContents
Next i

' 3. dùng hàm Split
For each cc in Split("sheet1!A5:G100, sheet2!B10:F18, sheet3!D6:K25", ", ")
Sheets(Split(cc, "!")(0)).Range(Split(cc, "!")(1)).ClearContents
Next sh
Em xin chân thành cảm ơn ạ
Bài đã được tự động gộp:

Thì dùng code sau:
Mã:
Sheets("sheet1").Range("A5:G100").ClearContents
Sheets("sheet2").Range("B10:F18").ClearContents
Sheets("sheet5").Range("D6:K25").ClearContents
Em xin chân thành cảm ơn ạ
 
Upvote 0
Web KT
Back
Top Bottom