title: Excel VBA looping through multiple worksheets
body: <p>VBA beginner here, I've got a little problem with program I'm working on.</p>
  
  <p>I need to copy data from last cell in column B from first worksheet and paste it into column A in another worksheet xws, and repeate this operation for five other worksheets with data.</p>
  
  <p>Here's the code, it doesn't work the way it should:</p>
  
  <pre><code>Sub exercise()
  
      Dim ws As Worksheet
      Dim rng As Range
      'Finding last row in column B
      Set rng = Range("B" &amp; Rows.Count).End(xlUp)
  
      For Each ws In ActiveWorkbook.Worksheets
          'Don't copy data from xws worksheet
          If ws.Name &lt;&gt; "xws" Then
              'Storing first copied data in A1
              If IsEmpty(Sheets("xws").[A1]) Then
                  rng.Copy Sheets("xws").Range("A" &amp; Rows.Count).End(xlUp)
              'Storing next copied data below previously filled cell
              Else
                  rng.Copy Sheets("xws").Range("A" &amp; Rows.Count).End(xlUp).Offset(1, 0)
              End If
          End If
      Next ws
  End Sub
  </code></pre>
  
  <p>There is a problem with ws. referring, but whenever I put it before rng in if statements or before range (set rng = ...) I get errors.</p>
  
  <p>Thanks in advance for any pointers.</p>