Help with code for macro

angus1

New Member
Joined
Sep 8, 2006
Messages
2
This is the first time I have wrote a macro so please keep it simple for me!

I have created buttons and want to assign a macro to each of them which will, in the cell above it, add 1 each time the button is clicked. It's to record information from a survey.

I realise that i will need a different macro for each button as it will have to refer to the particular cell above the button.

I think the macro code I need is something like:

ActiveCell.Value("A12")=ActiveCell.Value("A12")+1

but it keeps coming up with message saying VBA error 13 type mismatch and I've tried all sorts of variations but can't get it right.

Please help. thank you
:-?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi angus1, welcome to the board :-D

Try this:

Code:
Range("A12").FormulaR1C1 = Range("A12").Value + 1

Hope that helps.
 
Upvote 0
angus1

Welcome to the Mr Excel board!

I hope that I have understood correctly what you are trying to achieve. Instead of having lots of buttons and lots of macros, what about using the double click event? Try the code below. When you double-click a cell the value in that cell will be increased by 1 each time. If the cell contains text, nothing will happen.

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_BeforeDoubleClick(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range, Cancel <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN>)
    <SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">Resume</SPAN> <SPAN style="color:#00007F">Next</SPAN>
    Target.Value = Target.Value + 1
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
Thanks Airfix and Peter. I will have a go with both of those suggestions. Have only used excel in the past for basic things and looking forward to making much more use of it.

:-D
 
Upvote 0

Forum statistics

Threads
1,224,889
Messages
6,181,608
Members
453,055
Latest member
cope7895

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