Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Howto Code cmd button to increase value in a cell by 1?

Status
Not open for further replies.

Thom99

Programmer
Mar 6, 2002
2
US
Hi all! I KNOW this is probably WAY too beginner level a question, but here goes.

I'm trying to build a worksheet where the user can click on a commandbutton and a cell(lets say cell F3 of the worksheet) which starts with the number 0 will increase by 1 EACH time the button is clicked. I've gone CRAZY trying to find this in the Help file or in the MS forums? Does anyone have an idea how to do this? I'd REALLY appreciate the help! TIA..

thomas
thomas@jtbs.net
 
Assuming you are using a Command Button from the Controls Toolbox, the following code should work

Private Sub CommandButton1_Click()
Me.[F3] = Me.[F3] + 1
End Sub

To enter the code, from the controls Toolbar, click the design mode button (it's a blue triangle and pencil affair, like a designers desk) and then double click on teh button and enter the line Me.[F3] = Me.[F3] + 1 between the two pre-programmed lines. The final resul should look like the above.

AC
 
If you want to use the same button for a selected cell then the line
ActiveCell.value = ActiveCell.Value + 1
will work.

This, of course, could cause great grief if you click the
button without knowing where the activecell is.

dsb
 
Thank you both for your help! It worked-you guys ROCK!

thomas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top