トップ 差分 一覧 ping ソース 検索 ヘルプ PDF RSS ログイン

Excel VBA オートフィルタをで行が隠れているか判定



目次



記事一覧

キーワード

 

Cells(r, c).EntireRow.Hidden

 オートフィルタ済みで見えている行のみで上の行と重複があれば"1"を設定する例

Sub DuplicateRowCheck_Click()
    Const START_ROW As Integer = 4
    Const TARGET_COL As Integer = 5
    Const RESULT_COL As Integer = 6
    
    Dim r       As Long
    Dim pn      As String
    Dim s       As String
    Dim temp    As String
    Dim pre     As String
    Dim preRow  As Long
    
    r = START_ROW
    Do
        s = Cells(r, TARGET_COL).Text
        If Not Cells(r, TARGET_COL).EntireRow.Hidden Then
            temp = s
                        
            If pre = temp Then
                Cells(preRow, RESULT_COL).Value = "1"
                Cells(r, RESULT_COL).Value = "1"
            End If
            
            pre = temp
            preRow = r
        Else
            Cells(r, RESULT_COL).Value = ""
        End If
        r = r + 1
        DoEvents
    Loop While Trim(s) <> ""
    
    MsgBox "終了"
End Sub



YAGI Hiroto (piroto@a-net.email.ne.jp)
twitter http://twitter.com/pppiroto

Copyright© 矢木 浩人 All Rights Reserved.