title: VBA to loop through worksheets running code either doesnt loop or does loop but doesnt run code
body: <p>I am trying to cycle through all worksheets apart from one called 'summary', looking down a range in column A until finding a value, then looking in another workbook and getting some data, pasting it in, then carrying on until the end of column A range. Then it should move onto the next worksheet and repeat the process. I have been able to execute the code within the loop successfully, but only on the active worksheet. I've tried various iterations of the 'for each' statements. The current way seems to loop through the worksheets but doesn't run the code. </p>
  
  <p>How can i amend it so it works properly?</p>
  
  <pre><code>    Sub GetFlows()
  
  Dim rng As Range
  Dim row As Range
  Dim cell As Range
  Dim dem1 As String
  Dim WhereCell As Range
  Dim ws As Excel.Worksheet
  Dim iIndex As Integer
  
  Dim valueRng As Range
  Dim x As Long
  Dim y As Long
  
  
  Set rng = Range("A9:A200")
  
  For Each ws In ThisWorkbook.Worksheets
      If ws.Name &lt;&gt; "summary" Then
          ws.Activate
              For x = 1 To rng.Rows.Count
  
              dem1 = rng.Cells(x).Value
  
              If dem1 &lt;&gt; "" Then
                  Set WhereCell = ThisWorkbook.ActiveSheet.Range("A9:A200").Find(dem1, lookat:=xlPart)
                  Windows("GetFilenames v2.xlsm").Activate
                  Worksheets(dem1).Range("A1").CurrentRegion.Copy
                  WhereCell.Offset(, 2).PasteSpecial Paste:=xlPasteValues
                  Else
                  ThisWorkbook.Activate
              End If
  
              Next x
      End If
  Next ws
  
  
  End Sub
  </code></pre>