button counter macro by row

stevelizelsa

New Member
Joined
Sep 25, 2015
Messages
5
Hello. So I am making a spreadsheet that is full of button counters (110 + and 110 -). I found a thread from 2010 that gives a pretty good code for making the button add or subtract from a specific cell

~Sub count()
Dim x As Integer
x = Range("A1").Value
Range("A1").Value = x + 1
End Sub

however what I am looking for is a similar macro that I can attach to each button that simply has the button add or subtract from the same row that the button is located but in column B. That way if I insert a new row in the middle the buttons still add or subtract from the correct cell immediately to the left i.e.

a b c d

1 + -
2 + -

with the above code if I were to insert a row between 1 and 2 the button in b2 would become b3 but would still add to cell d2 instead of d3

a single code that said add to cell column b row same as button and could attach it individually to all the buttons instead of new code for each button that would be fantastic
Not sure if this is possible as I know very little of coding but any help would be highly appreciated
Thanks
Steve
 
Last edited:
That's a great script rpaulson. I was never able to understand what he wanted but I did not think he needed two buttons for every row.
Here is the code to do it without any buttons

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A1:C200")) Is Nothing Then _
      
r = ActiveCell.Row
c = ActiveCell.Column

If c = 1 Then x = 1
If c = 3 Then x = -1

Cells(r, "B") = Cells(r, "B") + x
End If
End Sub

rightclick on you worksheet then view code and pase it in
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Got it figured out, Darrens post worked like a charm, just needed to adjust it to give me my 110 rows of buttons, thanks a million.

Rpaulson.....that is a great idea but something about clicking a button gives me comfort!!

My Answer is this, to answer your question...row 5 tracks bananas, I have 12....I eat 1 I hit subtract, my monkey gives me 1 of his I hit add. If I add apples I didn't want the button that tracked bananas to start adding/subtracting to apples ;).

Darrens solution worked well and I still get my buttons...THANKS DARREN!!!
 
Upvote 0

Forum statistics

Threads
1,215,087
Messages
6,123,046
Members
449,092
Latest member
ikke

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