Perform a subtraction with a macro

Solved
jmtv Posted messages 9 Status Membre -  
jmtv Posted messages 9 Status Membre -
Hello,

I am currently creating a management system. Here is my objective.

I want that each time I submit (print) an invoice, the products be deducted from the inventory on another sheet.

I can't find the necessary macro that would allow me

to do = A1-A2 without A1 returning to the initial amount by changing A2.

I have this formula that I use for pagination of invoices. I would like to get the same result but instead of +1 I would have - "A1", and it seems that this is not as easy as just changing the 1 to A1... can you help me?

Range("E3").Select
num = Range("E3").Value
num = num + 1
Range("E3").Value = num

5 réponses

Gyrus Posted messages 3360 Status Membre 526
 
Hello jmtv,

I confirm that the macro works correctly.
If you enter 100 in E3 and 5 in E2, with each click on the button the value of E3 will be decremented by 5:
100...95...90... etc.

Private Sub CommandButton1_Click()
Range("E3") = Range("E3") - Range("E2")
End Sub

See you!
2
Gyrus Posted messages 3360 Status Membre 526
 
Hello,

The instructions you use for invoice pagination can be summarized as
Range("E3") = Range("E3") + 1

Similarly, to subtract the value of A2 from A1
Range("A1") = Range("A1") - Range("A2") 

A+
0
jmtv Posted messages 9 Status Membre
 
Thank you very much, I will try this immediately!
0
jmtv Posted messages 9 Status Membre
 
Hello Gyrus,

your macro is not working...

when I use

Range("E3").Select
num = Range("E3").Value
num = num + 1
Range("E3").Value = num

this is with a button. And my goal is that instead of adding +1 each time I click (which is the formula above), the amount should be the negative of the number X indicated in a specific cell, let's say E2.
0
jmtv Posted messages 9 Status Membre
 
Well, you have to understand that I'm a novice in this area haha! Thank you very much Gyrus, the command is indeed working!

Thanks again
0