title: vba - assign value of cell from another worksheet to a variable
body: <p>I cannot cope with the following issue. I have in a module certain code. This code is working well when I'm in the sheet2. When skipping to sheet1 and run macro it returns me 0. I'd appreciate if you could point at the mistake I've done.</p>
  
  <pre><code>Public Sub Test()
  
  Dim ws As Worksheet
  Dim cost As Double
  
  Set ws = Sheets("Sheet1")
  
  cost = Worksheets("Sheet2").Application.Sum(Range("A2:A10"))
  MsgBox cost
  ws.Range("C2") = cost
  
  End Sub
  </code></pre>