langtuchungtinh360
Thành viên đã dừng hoạt động
- Tham gia
- 7/10/13
- Bài viết
- 1,062
- Được thích
- 334
em có xem và biết được Fint (Ctrl + F) có thể tìm được những ô có định dạng theo yêu cầunội dung và kết quả mong muốn em có nêu trong file đính kèm
Sub Macro1()
'
' Macro1 Macro
'
'
    With Application.FindFormat
        .WrapText = False
        .ShrinkToFit = False
        .MergeCells = True
    End With
    Cells.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=True).Activate
    Cells.FindNext(After:=ActiveCell).Activate
    Cells.FindNext(After:=ActiveCell).Activate
    Cells.FindNext(After:=ActiveCell).Activate
End SubBạn cứ For Next bình thường đi cho khỏeem có xem và biết được Fint (Ctrl + F) có thể tìm được những ô có định dạng theo yêu cầu
nhưng khi ghi macro rồi chạy lại thì nó lại ra sai
chỉ tìm được 1 lần rồi mấy lần sau toàn chạy tới 1 ô tiếp theo không chứ không tìm được nữa.Mã:Sub Macro1() ' ' Macro1 Macro ' ' With Application.FindFormat .WrapText = False .ShrinkToFit = False .MergeCells = True End With Cells.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _ xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _ , SearchFormat:=True).Activate Cells.FindNext(After:=ActiveCell).Activate Cells.FindNext(After:=ActiveCell).Activate Cells.FindNext(After:=ActiveCell).Activate End Sub
---------------------
em nhớ là có thấy 1 đề tài là xác định 1 vùng có nằm trong (thuộc) 1 vùng khác hay không, nhưng giờ tìm lại không biết ở đâu mà tìm. bác nào biết cho em xin link.
Sub Macro1()
Dim Dic1 As Object
Dim Rn As Range, i As Long
Set Dic1 = CreateObject("Scripting.Dictionary")
    With Worksheets(1).Range("A1:Z100")
        Application.FindFormat.MergeCells = True
        Set Rn = .Find("", SearchFormat:=True)
        If Not Rn Is Nothing Then
            Do
                If Not Dic1.exists(Rn.MergeArea.Address(0, 0)) Then
                    i = i + 1
                    Dic1.Add Rn.MergeArea.Address(0, 0), i
                End If
                Debug.Print Rn.MergeArea.Address(0, 0)
                Set Rn = .Find("", After:=Rn, SearchFormat:=True)
            Loop While Rn.MergeCells = True And Not Dic1.exists(Rn.MergeArea.Address(0, 0))
        End If
    End With
End Sub