Quangdz0512
Thành viên mới
- Tham gia
- 29/7/23
- Bài viết
- 40
- Được thích
- 21
Sub TimKiem()
Dim Rws As Long, W As Integer
Dim Rng As Range, sRng As Range
Dim MyAdd As String
Rws = Sheet1.UsedRange.Rows.Count
Set Rng = [d1].Resize(Rws)
ReDim Arr(1 To Rws, 1 To 2) As String
[H3].Resize(Rws, 2).Clear
Set sRng = Rng.Find("X", , xlFormulas, xlWhole)
MyAdd = sRng.Address
Do
W = W + 1
Arr(W, 1) = sRng.Offset(, -3).Value
Arr(W, 2) = sRng.Offset(, -2).Value
Set sRng = Rng.FindNext(sRng)
Loop While Not sRng Is Nothing And sRng.Address <> MyAdd
If W Then
[H3].Resize(W, 2).Value = Arr()
[H3].Resize(W, 2).Interior.ColorIndex = 34 + (W Mod 9)
End If
End Sub
Cảm ơn chú SA!→ → → ← ← ←PHP:Sub TimKiem() Dim Rws As Long, W As Integer Dim Rng As Range, sRng As Range Dim MyAdd As String Rws = Sheet1.UsedRange.Rows.Count Set Rng = [d1].Resize(Rws) ReDim Arr(1 To Rws, 1 To 2) As String [H3].Resize(Rws, 2).Clear Set sRng = Rng.Find("X", , xlFormulas, xlWhole) MyAdd = sRng.Address Do W = W + 1 Arr(W, 1) = sRng.Offset(, -3).Value Arr(W, 2) = sRng.Offset(, -2).Value Set sRng = Rng.FindNext(sRng) Loop While Not sRng Is Nothing And sRng.Address <> MyAdd If W Then [H3].Resize(W, 2).Value = Arr() [H3].Resize(W, 2).Interior.ColorIndex = 34 + (W Mod 9) End If End Sub
Chúc vui!
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rws As Long, W As Integer
Dim Rng As Range, sRng As Range
Dim MyAdd As String
If Not Intersect(Target, [I2]) Is Nothing Then
Rws = Sheet1.UsedRange.Rows.Count
Set Rng = [A1].Resize(Rws)
ReDim Arr(1 To Rws, 1 To 2) As String
[H3].Resize(Rws, 2).Clear
Set sRng = Rng.Find(Target.Value, , xlFormulas, xlWhole)
7 If Not sRng Is Nothing Then
MyAdd = sRng.Address
Do
If Cells(sRng.Row, "D").Value = "X" Then
W = W + 1
Arr(W, 1) = sRng.Value
Arr(W, 2) = sRng.Offset(, 1).Value
End If
Set sRng = Rng.FindNext(sRng)
Loop While Not sRng Is Nothing And sRng.Address <> MyAdd
17 End If
If W Then
[H3].Resize(W, 2).Value = Arr()
[H3].Resize(W, 2).Interior.ColorIndex = 34 + (W Mod 9)
End If
End If
End Sub