Sub Macro2()
Dim m, n As Long
With Sheet1
For m = 2 To 7
For n = 11 To 20
If InStr(.Cells(m, n), .Range("D1").Value) <> 0 Then
.Cells(m, n) = Empty
'.Cells(m, n) = Replace(.Cells(m, n), .Range("D1").Value, "")
End If
Next n
Next m
End With
End Sub
Sub gpeFind()
Dim Rng As Range, sRng As Range
Dim MyAdd As String: Dim J As Long
Set Rng = [K3].CurrentRegion
Set sRng = Rng.Find([D2].Value, , xlFormulas, xlWhole)
If sRng Is Nothing Then
MsgBox "Nothing"
Else
MyAdd = sRng.Address
Do
J = J + 1
MsgBox sRng.Address, , Str(J)
Set sRng = Rng.FindNext(sRng)
Loop While Not sRng Is Nothing And sRng.Address <> MyAdd
End If
End Sub
Chuẩn của phương thức FIND() nè, mại zô:
PHP:Sub gpeFind() Dim Rng As Range, sRng As Range Dim MyAdd As String: Dim J As Long Set Rng = [K3].CurrentRegion Set sRng = Rng.Find([D2].Value, , xlFormulas, xlWhole) If sRng Is Nothing Then MsgBox "Nothing" Else MyAdd = sRng.Address Do J = J + 1 MsgBox sRng.Address, , Str(J) Set sRng = Rng.FindNext(sRng) Loop While Not sRng Is Nothing And sRng.Address <> MyAdd End If End Sub
Sub gpeTimVaXoa()
Dim Rng As Range, sRng As Range, dRg As Range
Dim MyAdd As String: Dim J As Long
Set Rng = [K3].CurrentRegion
Set sRng = Rng.Find([D1].Value, , xlFormulas, xlWhole)
If sRng Is Nothing Then
MsgBox "Nothing"
Else
MyAdd = sRng.Address
Do
If dRg Is Nothing Then
Set dRg = sRng
Else
Set dRg = Union(dRg, sRng)
End If
Set sRng = Rng.FindNext(sRng)
Loop While Not sRng Is Nothing And sRng.Address <> MyAdd
MsgBox dRg.Cells.Count
If Not dRg Is Nothing Then dRg.Value = Space(0)
End If
End Sub
Thắc mắc chút là chỗ này sao không dùngIf Not dRg Is Nothing Then dRg.Value = Space(0)
/-)ể có cái mà ôn tập & tự học ý mà!Thắc mắc chút là chỗ này sao không dùng
If Not dRg Is Nothing Then dRg.ClearContents