Add and subtract cells based on Form Button Position

LeoScibi

New Member
Joined
Dec 13, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I need to record movement of stock.
When I click the + Button, I need to subtract 1 from the inventory column and add 1 to the correct location.

button.png

In this forum I found the following code that allows me to write an "X" in the cell, but I can't figure out how to add1 and subtract1 istead.

Public Sub Button_Click()
With ActiveSheet.Buttons(Application.Caller)
Cells(.TopLeftCell.Row, .BottomRightCell.Column + 3).Value = "X"
End With
End Sub

Could you please help me out with this?
Thanks in advance!
Leo
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try.
The codes are not tested.

The code is for the button + under the blue cell.
VBA Code:
Public Sub Button_Click()
    With ActiveSheet.Buttons(Application.Caller)
        'Location  +1
        Cells(.TopLeftCell.Row, .BottomRightCell.Column + 4).Value = Cells(.TopLeftCell.Row, .BottomRightCell.Column + 4).Value + 1
        'Inventory -1
        Cells(.TopLeftCell.Row, .BottomRightCell.Column - 1).Value = Cells(.TopLeftCell.Row, .BottomRightCell.Column - 1).Value + 1
    End With
End Sub

And the following code should be for the button + under the red cell
VBA Code:
Public Sub Button_Click()
    With ActiveSheet.Buttons(Application.Caller)
        'Location  +1
        Cells(.TopLeftCell.Row, .BottomRightCell.Column + 4).Value = Cells(.TopLeftCell.Row, .BottomRightCell.Column + 4).Value + 1
        'Inventory -1
        Cells(.TopLeftCell.Row, .BottomRightCell.Column - 2).Value = Cells(.TopLeftCell.Row, .BottomRightCell.Column - 2).Value + 1
    End With
End Sub

And this for the button + under for the green cell
VBA Code:
Public Sub Button_Click()
    With ActiveSheet.Buttons(Application.Caller)
        'Location  +1
        Cells(.TopLeftCell.Row, .BottomRightCell.Column + 4).Value = Cells(.TopLeftCell.Row, .BottomRightCell.Column + 4).Value + 1
        'Inventory -1
        Cells(.TopLeftCell.Row, .BottomRightCell.Column - 3).Value = Cells(.TopLeftCell.Row, .BottomRightCell.Column - 3).Value + 1
    End With
End Sub
 
Upvote 0
Solution
That's amazing,
Thank you so much for the quick fix.

I had to tweak it slightly but it works perfectly now.

Public Sub Button_Click_Location_1()
With ActiveSheet.Buttons(Application.Caller)
'Location +1
Cells(.TopLeftCell.Row, .BottomRightCell.Column + 3).Value = Cells(.TopLeftCell.Row, .BottomRightCell.Column + 3).Value + 1
'Inventory -1
Cells(.TopLeftCell.Row, .BottomRightCell.Column - 2).Value = Cells(.TopLeftCell.Row, .BottomRightCell.Column - 2).Value - 1
End With
End Sub

Public Sub Button_Click_Location_2()
With ActiveSheet.Buttons(Application.Caller)
'Location +1
Cells(.TopLeftCell.Row, .BottomRightCell.Column + 3).Value = Cells(.TopLeftCell.Row, .BottomRightCell.Column + 3).Value + 1
'Inventory -1
Cells(.TopLeftCell.Row, .BottomRightCell.Column - 3).Value = Cells(.TopLeftCell.Row, .BottomRightCell.Column - 3).Value - 1
End With
End Sub

Public Sub Button_Click_Location_3()
With ActiveSheet.Buttons(Application.Caller)
'Location +1
Cells(.TopLeftCell.Row, .BottomRightCell.Column + 3).Value = Cells(.TopLeftCell.Row, .BottomRightCell.Column + 3).Value + 1
'Inventory -1
Cells(.TopLeftCell.Row, .BottomRightCell.Column - 4).Value = Cells(.TopLeftCell.Row, .BottomRightCell.Column - 4).Value - 1
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,111
Messages
6,123,155
Members
449,098
Latest member
Doanvanhieu

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