トップ 一覧 ping 検索 ヘルプ 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