Row Function Maths ClearContents
<p>very new to excel VBA and have been working on an exercise to create a purchase order sheet with a userform. </p>

<p>Have run into a problem when trying to clear rows based on a couple of variables. </p>

<p>I have a button to clear the row that has just been added to the sheet, with the following code: </p>

<pre><code>Private Sub RemovePrevious_Click()

'Removes last line of PO

If LineItemTotal &gt; 1 Then

Rows(LineItemTotal + POrowstart - 1).SpecialCells(xlCellTypeConstants).ClearContents

End If

End Sub
</code></pre>

<p>LineItemTotal is a range on the sheet that increases as new lines are added. It is declared publicly with POrowstart at the beginning of the userform: </p>

<pre><code>Private LineItemTotal As Integer
Private POrowstart As Integer
</code></pre>

<p>They are then assigned in a different sub: </p>

<pre><code>LineItemTotal = Range("LineItemTotal")
POrowstart = 10
</code></pre>

<p>The problem is that when using the button to run the removeprevious sub, the maths isn't adding up. For instance, when LineItemTotal is 3, it should delete row 12 (the correct one), but it instead deletes row 11. If you press it again (LineItemTotal is now at 2, so should delete 11) it throws an error 'no cells were found' as if it is deleting 11, but it has already mistakenly cleared this. </p>

<p>I have SpecialCells in the code as there are formulas on the row I would like to keep. </p>

<p>Thanks for any help with this. </p>