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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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,748
Messages
6,126,654
Members
449,326
Latest member
asp123

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