title: Vba loop through all open workbook and comparing those workbook name with some value and do some operations
body: <p>The code is giving me an error in the line <code>'**ERROR HERE</code></p>
  
  <p>I have several workbooks open which names are dynamic, Each workbook has a worksheet named "CC". I want to compare the value of D column with that workbook name in "CC" worksheet in all open workbooks and if that workbook name is not equal to column D value of worksheet CC then remove those rows from worksheet CC.</p>
  
  <pre><code>Sub filter()
      Dim wbs As Workbooks
      Dim wb As Workbook
      Set wbs = Application.Workbooks
  
      For Each wb In wbs
      For j = lastRowy(Worksheets("CC")) To 1 Step -1
          If wb.Name &lt;&gt; wb.Worksheets("CC").Cells(j, "D").Value Then '**ERROR HERE
              Rows(j).Delete
          End If
          Next j
      Next wb         
  End Sub
  
  Function lastRowy(sh As Worksheet)
      On Error Resume Next
      lastRowy = sh.Cells.Find(what:="*", _
          After:=sh.Range("A1"), _
          LookAt:=xlPart, _
          LookIn:=xlValues, _
          SearchOrder:=xlByRows, _
          SearchDirection:=xlPrevious, _
          MatchCase:=False).Row
      On Error GoTo 0
  End Function
  </code></pre>