VBA item comparison and amount additions

Asked

Viewed 59 times

0

Personal hj I came to insert the image description here a doubt that will be very specific I do not know what problem of this code in vdd Xp I spent a few days breaking my head in it but I have not found a solution I used a loop for it to repeat a condition so that it does not stop until reach the last filled cell.

 Sub finalizaVenda()

v_id = Sheets("venda").Cells(3, 8)
g_id = Sheets("ger").Cells(3, 1)

i = 3

val_venda = Sheets("venda").Range("k3").Value
val_ger = Sheets("ger").Cells(i, 1).Value

indConsulta = Sheets("venda").Range("H1048576").End(xlUp).row
Sheets("venda").Activate
Sheets("venda").Range("h3").Select

Do While ActiveCell.row >= 3

If (v_id = g_id) Then

val_ger = val_venda
ActiveCell.Offset(-1, 0).Select
i = i + 1
Debug.Print val_ger
Debug.Print val_venda
Sheets("ger").Cells(i, 3).Select

Else

i = i + 1

End If
Loop
End Sub

what was to happen was this : all id’s that are presented in a period of H3 to H21 of the sales table, would have to be compared to column The one in the Ger table that has all registered id’s. If the period id H3 to H21 of the sales table match some id of the column A of table Ger ent the amount that is imposed in the column QUANTITY of table sale must be "played" in the cell Q.sell according to your id so that the value of K3(sale) can be cleaned and the cell which is filled with this value in Ger table can receive other values + the msm good an example would be the following situation:

I inform the id and quantity of sale(sales table) id = 1 & quantity = 5 when I finish the sale I click on the button, and it plays this amount in the Ger table, in this case the E3 cell would be filled with 5 because the id is 1. if I come to make another sale with msm id it adds the amount I reported on top of the amount 5 adding up the two values.

tabela venda tabela ger

  • You are performing a while loop from line 3 to the last line of the spreadsheet with Do While ActiveCell.row >= 3, try to use Do While ActiveCell.row >= indConsulta and try to avoid using the .Select

  • opa, good night amg, I did what you told me to do the same mistake. It enters a loop and simply hangs the program, on the while loop I was using the while as a condition to perform another condition, type.. (while the active cell’s Indice Row is smaller than the last filled line ) if (the id in the column matches the id in the table) then (the amount of product will be msm + the amount entered in the Amount column ). select it was used to select a cell and it will be used as a cursor running through the id column, well at least that was my idea xD

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.