nguyenquan
Thành viên mới

- Tham gia
- 3/6/08
- Bài viết
- 4
- Được thích
- 0
Mình có sưu tầm được đoạn code so sánh giữa 2 sheet (sheet1 và sheet2), nếu muốn so sánh sheet1 với sheet3 thì phải mở code lên sửa. Xin hỏi có cách nào ví dụ như ở ô A1 của sheet1 nhập tên sheet3 thì vba sẽ so sánh giữa sheet1 và sheet3.
Đoạn code mình sưu tầm được như sau:
(phần màu đỏ là phần muốn thay dổi)
Option Explicit
Sub SoTrung()
Dim Sh As Worksheet, Rng As Range, sRng As Range, Clls As Range
Dim MyColor As Byte
Sheet1.Select: Set Sh = Sheet2
[B3].CurrentRegion.Offset(1).Interior.ColorIndex = 0
Sh.Cells.Interior.ColorIndex = 0
Set Rng = Sh.Range("G1:G" & Sh.[G65500].End(xlUp).Row)
For Each Clls In Range("G1:G" & [G65500].End(xlUp).Row)
Set sRng = Rng.Find(Clls.Value, , xlFormulas, xlWhole)
If Not sRng Is Nothing Then
MyColor = 33
Clls.Resize(, 1).Interior.ColorIndex = MyColor
sRng.Resize(, 1).Interior.ColorIndex = MyColor
End If
Next Clls
End Sub
Cảm ơn mọi người
Đoạn code mình sưu tầm được như sau:
(phần màu đỏ là phần muốn thay dổi)
Option Explicit
Sub SoTrung()
Dim Sh As Worksheet, Rng As Range, sRng As Range, Clls As Range
Dim MyColor As Byte
Sheet1.Select: Set Sh = Sheet2
[B3].CurrentRegion.Offset(1).Interior.ColorIndex = 0
Sh.Cells.Interior.ColorIndex = 0
Set Rng = Sh.Range("G1:G" & Sh.[G65500].End(xlUp).Row)
For Each Clls In Range("G1:G" & [G65500].End(xlUp).Row)
Set sRng = Rng.Find(Clls.Value, , xlFormulas, xlWhole)
If Not sRng Is Nothing Then
MyColor = 33
Clls.Resize(, 1).Interior.ColorIndex = MyColor
sRng.Resize(, 1).Interior.ColorIndex = MyColor
End If
Next Clls
End Sub
Cảm ơn mọi người