- Tham gia
- 23/3/16
- Bài viết
- 705
- Được thích
- 52
Sub GPE()
Dim Rng As Range, c As Range, firstAddress As String
With Sheet1.Range("B3:B23")
Set c = .Find("a", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Set Rng = c
Do
Set c = .FindNext(c)
If Not c Is Nothing Then Set Rng = Union(Rng, c)
Loop While Not c Is Nothing And c.Address <> firstAddress
Rng.Select
End If
End With
End Sub
Dùng code này thử xem
Mã:Sub GPE() Dim Rng As Range, c As Range, firstAddress As String With Sheet1.Range("B3:B23") Set c = .Find("a", LookIn:=xlValues) If Not c Is Nothing Then firstAddress = c.Address Set Rng = c Do Set c = .FindNext(c) If Not c Is Nothing Then Set Rng = Union(Rng, c) Loop While Not c Is Nothing And c.Address <> firstAddress Rng.Select End If End With End Sub
Tôi thấy nó chọn đúng mà bạn, tức là ô nào chứa giá trị ab cũng chọn luôn mà. Còn nếu muốn chọn chính xác giá trị a không (không chọn giá trị ab) thì sửa code lại một chút.Code anh sai rồi. Chỉ bôi đen những ô nào chỉ có 1 ký tự "a" duy nhất thôi còn "ab" cũng không được bôi
Sub GPE()
Dim Rng As Range, c As Range, firstAddress As String
With Sheet1.Range("B3:B23")
Set c = .Find("a", , xlValues, xlWhole, , , True)
If Not c Is Nothing Then
firstAddress = c.Address
Set Rng = c
Do
Set c = .FindNext(c)
If Not c Is Nothing Then Set Rng = Union(Rng, c)
Loop While Not c Is Nothing And c.Address <> firstAddress
Rng.Select
End If
End With
End Sub
Sửa lại vầy.Code anh sai rồi. Chỉ bôi đen những ô nào chỉ có 1 ký tự "a" duy nhất thôi còn "ab" cũng không được bôi
Sub GPE()
Dim Rng As Range, c As Range, firstAddress As String
With Sheet1.Range("B3:B23")
Set c = .Find(What:="a", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False)
If Not c Is Nothing Then
firstAddress = c.Address
Set Rng = c
Do
Set c = .FindNext(c)
If Not c Is Nothing Then Set Rng = Union(Rng, c)
Loop While Not c Is Nothing And c.Address <> firstAddress
Rng.Select
End If
End With
End Sub
Sao không Filter "a"?
Select xong ngồi ngắm chơi?
Sửa lại vầy.
Mã:Sub GPE() Dim Rng As Range, c As Range, firstAddress As String With Sheet1.Range("B3:B23") Set c = .Find(What:="a", After:=ActiveCell, LookIn:=xlValues, LookAt:= _ xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _ , SearchFormat:=False) If Not c Is Nothing Then firstAddress = c.Address Set Rng = c Do Set c = .FindNext(c) If Not c Is Nothing Then Set Rng = Union(Rng, c) Loop While Not c Is Nothing And c.Address <> firstAddress Rng.Select End If End With End Sub
@giaiphap : viết code xong mà người nhận code có test không mà phán
là thấy chạy được rồi đó...Code anh sai rồi...
Select xong ngồi ngắm chơi?
Sửa lại vầy.
Mã:Sub GPE() Dim Rng As Range, c As Range, firstAddress As String With Sheet1.Range("B3:B23") Set c = .Find(What:="a", After:=ActiveCell, LookIn:=xlValues, LookAt:= _ xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _ , SearchFormat:=False) If Not c Is Nothing Then firstAddress = c.Address Set Rng = c Do Set c = .FindNext(c) If Not c Is Nothing Then Set Rng = Union(Rng, c) Loop While Not c Is Nothing And c.Address <> firstAddress Rng.Select End If End With End Sub
Sao không Filter "a"?
Chủ thớt này khó tính lắm, không bao giờ chấp nhận phương án 'b'.
Nếu từ đầu bạn hỏi cách ẩn dòng có chữ "a" thì xong rồi.ANh ba tê giúp em đi. Thật ra e Muốn select những ô Nào có chử "a" để em ẩn cái dòng đó, để khi in ra dòng đó không xuất hiện. Thank a
Public Sub GPE()
Dim Cll As Range, R As Long
R = Range("B60000").End(xlUp).Row
For Each Cll In Range("B1:B" & R)
If UCase(Cll) = "A" Then Cll.EntireRow.Hidden = True
Next Cll
End Sub
Vẫn câu hỏi cũ: Sao không dùng Filter? (mắc mớ gì phải For... Next?)Nếu từ đầu bạn hỏi cách ẩn dòng có chữ "a" thì xong rồi.
Select mà chẳng biết làm gì thì ai mà hiểu, mỗi người làm mỗi kiểu làm sao bạn áp dụng?
PHP:Public Sub GPE() Dim Cll As Range, R As Long R = Range("B60000").End(xlUp).Row For Each Cll In Range("B1:B" & R) If UCase(Cll) = "A" Then Cll.EntireRow.Hidden = True Next Cll End Sub