ステートメント制御文の使用例7


使用例7

出現値を重複なしで抽出し、該当する記号(○印)の件数をカウントする。


 


Sub Chushutsu()
Dim c As Range
Dim la, lb As Integer
Dim rs As Long
With Worksheets(1)
  '出現値を重複なしで抽出
  la = .Range("a1").CurrentRegion.Rows.Count  'データ最終行
  r = .Rows.Count                             'シート最終行
  With .Range("a1:a" & CStr(la))
    For i = 1 To la
    Set c = .Find(i, LookIn:=xlValues)        '新番号を検索
      If Not c Is Nothing Then
        firstAddress = c.Address      '最初の番号のアドレス
        Cells(r, 5).End(xlUp).Offset(1).Select  '入力行選択
        Selection.Value = c.Value           '検索番号を入力
        Selection.Offset(, 1).Value = _
            c.Offset(, 1).Value         '対応する氏名を入力
      End If
    Next i
  End With
  
  '該当の記号(○印)の件数をカウント
  lb = .Range("e1").CurrentRegion.Rows.Count
  For j = 1 To lb - 1
    .Cells(j + 1, 7).Value = _
      "=SUMPRODUCT((a2:a" & la & "=" & j & ")*(c2:c" & la & "=" & """○""))"
      'つまり G2 には、=SUMPRODUCT((a2:a11=1)*(c2:c11="○")) が入力される
  Next j
End With
End Sub

                                                                     back top