Excel Visual Basic Run-time error '1004' when initializing a variable <p>I am learning visual basic and this script I'm using is coming up with an error when I am initializing the variable <code>i</code>.</p> <p>I'm not sure what the problem is but I am getting the error message:</p> <blockquote> <p>Run-time error '1004': Application-defined or object-defined error</p> </blockquote> <p>Here is my code:</p> <pre><code>Sub excelmacro() Sheets("Sheet1").Select Range("A1").Select Sheets("Sheet2").Select Range("B1").Select i = 1 While i &lt;&gt; 10 If Len(ActiveCell.Value) &gt; 1 Then Sheets("Sheet1").Select xname = Right(ActiveCell.Value, Len(ActiveCell.Value) - 6) xsalary = Right(ActiveCell.Value, Len(ActiveCell.Offset(2, 0).Value) - 8) xdesignation = Right(ActiveCell.Value, Len(ActiveCell.Offset(1, 0).Value) - 13) Sheets("Sheet2").Select ActiveCell.Value = xname ActiveCell.Offset(0, 1).Value = xdesig ActiveCell.Offset(0, 3).Value = xsalary ActiveCell.Offset(1, 0).Select Sheets("Sheet1").Select ActiveCell.Offset(3, 0).Select Else i = 10 End If Wend End Sub </code></pre>