title: Calculating cell values
body: <p>I am trying to write VBA code for reading a value from a different worksheet and then calculating a value in the current one. The code I wrote:</p>
  
  <pre><code>Function tell_me2()
  Dim my_range As Range
  Dim sheet_number As Integer
  Dim my_row As Integer
  Dim my_column As Integer
  Dim my_value As Integer
  sheet_number = ActiveSheet.Index
  my_row = ActiveCell.Row
  my_column = ActiveCell.Column
  'MsgBox (sheet_number)
  'MsgBox (my_row)
  'MsgBox (my_column)
  'MsgBox (Worksheets(sheet_number - 1).Cells(my_row, my_column - 1))
  my_value = Worksheets(sheet_number - 1).Cells(my_row, my_column - 1)
  'my_value = my_range.Value
  MsgBox ("12 " &amp; my_value)
  'my_range = Worksheets(sheet_number - 1).Cells(my_row - 1, my_column - 1)
  'my_range.Activate
  Set my_range = Worksheets(sheet_number).Cells(my_row, my_column + 1)
  ' have also tried
  Worksheets(sheet_number).Cells(my_row, my_column + 1) = my_value - 12
  my_range.Value = my_value - 12
  MsgBox ("All Done!")
  End Function
  </code></pre>
  
  <p>When debugging I can see that my_value contains the correct value but then I get a #VALUE error rather than the value I want in the correct cell.  </p>
  
  <p>Could someone please point me in the right direction?</p>