I would like for my command to repeat through each row, at the moment it only runs on 1 row

Roberto 20 Reputation points
2023-10-02T13:47:17.27+00:00
I have the  current VBA
Sub Subtract()
cPart = Sheet3.Range("a2, a1000")
cQty = Sheet3.Range("b2, b1000")
'loop

lastrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).row
For i = 2 To lastrow
    If Sheet1.Cells(i, 1) = cPart Then
        'found it
        Sheet1.Cells(i, 4) = Sheet1.Cells(i, 4) - cQty
        Exit Sub

    End If

Next i

End Sub
This only runs for 1 row, but I would like for it to repeat through every active row.. Please help
Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
5,375 questions
Bing Spell Check
Bing Spell Check
A Bing service that detects and corrects spelling mistakes in your app.
36 questions
Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,915 questions
Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
2,054 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
40,633 questions
{count} votes

Accepted answer
  1. Viorel 118.6K Reputation points
    2023-10-02T14:30:59.21+00:00

    Try to remove the Exit Sub line.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.