2nd loop doesn't work

ping0775

New Member
Joined
Jul 18, 2022
Messages
40
Office Version
  1. 2007
Platform
  1. Windows
Dim counta, r As Long
counta = Sheets("InvoiceDatabase").Cells(Rows.count, "B").End(xlUp).Row
countb = Sheets("SalesReceiptDocList").Cells(Rows.count, "C").End(xlUp).Row
t = 3
u = 3
Do While t <= counta
Sheet4.Range("ai" & t).Value = Sheet4.Range("w" & t).Value
invno = Sheet4.Range("b" & t).Value

Do While u <= countb
If Left(Sheet19.Cells(u, 3), 12) = invno Then
paid = Format(Sheet19.Cells(u, "F"), "####0.00") 'Paid
sum = sum + Val(paid)
sum = Format(sum, "#,##0.00")
Sheet4.Range("ai" & t).Value = Val(Sheet4.Range("w" & t).Value) - sum
End If
u = u + 1
Loop

t = t + 1
Loop
End If



End Sub
invno = Sheet4.Range("b" & t).Value
this code carry INV01,02,03,04,05

but when it loop in second sheet19, why it only run the INV01?
how to make it continue loop INV01,02,03,04,05 in second loop?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try stepping through your code and seeing what each of the variables are set to. The second loop executes while t is less than or equal to countb, if it only runs once then it'll be down to the loop conditions.

Little pro tip: use meaningful variable names and don't duplicate names that are already in use. Sum and CountA are both available functions to use in VBA.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top