Button linked to counter VBA code

sconchiti

New Member
Joined
Aug 24, 2008
Messages
2
I'm a VBA newb, and although I've searched and searched, I can not find an answer to what seems like a simple question.

I have added buttons to several cells and clicking that button runs a counter macro. Clicking on the button in cell c5 runs the following macro which I found online:

Sub Macro1()
mycount = Range("c5") + 1
Range("c5") = mycount
End Sub

The value in c5 goes up by 1 as expected.

The problem is that when I insert a new row above row 5, the button moves down so it stays in the same cell, but when the button is pressed it adds 1 to the "new" c5. How do I get the macro to add the amount to the "old" cell which is now c6?

Thanks,
Dan
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
You could link all of your buttons to this code. Perhaps add an .Offset to the With line.
Code:
Sub increaseByOne()
    With ActiveSheet.Shapes(Application.Caller).TopLeftCell
        .Value = Val(CStr(.Value)) + 1
    End With
End Sub
 
Upvote 0
Wow. That was a ridiculously fast answer. And it works! No .Offset needed.

I really appreciate the help. I am only beginning to understand how powerful macros and VBA can be. Thanks for the help. You saved me a ton of time.

Dan
 
Upvote 0

Forum statistics

Threads
1,215,477
Messages
6,125,036
Members
449,205
Latest member
Eggy66

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