I am trying to write my first vba macro for excel 2010. It needs to do some long calculations for 200,000 rows and needs to populate 2 adjacent cells on the active row. The following VBA function is a crude first attempt to accomplish the above. Problem is while executing the macro, I get #value! error. If I remove "cells" and .Value lines, it works fine and populates the activecell with appropriate value. What am I doing wrong?
Appreciate the help very much.
Public Function someCalculation() As Integer
Dim r As Range
Dim nrow, ncol As Integer
nrow = ActiveCell.Row
ncol = ActiveCell.Column
r = Cells(nrow, ncol + 1)
r.Value = nrow * 100 + ncol
someCalculation = nrow * 1000 + ncol
End Function