#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10
Default Command button macro

I want to assign a macro to a command button so that it increases the value
of a cell by 1
Thanks in advance if you can help me.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default Command button macro

Place this code in a standard code module and assign it to a coomand button...

Public Sub Increment()
Range("A1").Value = Range("A1").Value + 1
End Sub
--
HTH...

Jim Thomlinson


"Mark N" wrote:

I want to assign a macro to a command button so that it increases the value
of a cell by 1
Thanks in advance if you can help me.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,696
Default Command button macro

So, the Macro will be Range("A1") = Range("A1") + 1

And just add a command button and assign the macro.

"Mark N" wrote:

I want to assign a macro to a command button so that it increases the value
of a cell by 1
Thanks in advance if you can help me.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10
Default Command button macro

Thanks Jim,
I forgot but i would need to reset the cell also. do i need another command
button to reset?

"Jim Thomlinson" wrote:

Place this code in a standard code module and assign it to a coomand button...

Public Sub Increment()
Range("A1").Value = Range("A1").Value + 1
End Sub
--
HTH...

Jim Thomlinson


"Mark N" wrote:

I want to assign a macro to a command button so that it increases the value
of a cell by 1
Thanks in advance if you can help me.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,696
Default Command button macro

Public Sub Increment()
Range("A1").Value = 0
Range("A1").Value = Range("A1").Value + 1
End Sub

Would reset the cell, but then that means you're always goingto have 0, then
1........

"Mark N" wrote:

Thanks Jim,
I forgot but i would need to reset the cell also. do i need another command
button to reset?

"Jim Thomlinson" wrote:

Place this code in a standard code module and assign it to a coomand button...

Public Sub Increment()
Range("A1").Value = Range("A1").Value + 1
End Sub
--
HTH...

Jim Thomlinson


"Mark N" wrote:

I want to assign a macro to a command button so that it increases the value
of a cell by 1
Thanks in advance if you can help me.



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default Command button macro

How you wish to rest is up to you. A command button seems logical. In that
case attach this code

public sub ResetTo0()
range("A1").value = 0
end sub
--
HTH...

Jim Thomlinson


"Mark N" wrote:

Thanks Jim,
I forgot but i would need to reset the cell also. do i need another command
button to reset?

"Jim Thomlinson" wrote:

Place this code in a standard code module and assign it to a coomand button...

Public Sub Increment()
Range("A1").Value = Range("A1").Value + 1
End Sub
--
HTH...

Jim Thomlinson


"Mark N" wrote:

I want to assign a macro to a command button so that it increases the value
of a cell by 1
Thanks in advance if you can help me.

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Command button macro

First, create the follow procedures in a VBA module.

Public Sub IncrementSpecificCell()
With ThisWorkbook.Worksheets("Sheet1").Range("A1")
.Value = .Value + 1
End With
End Sub

Public Sub IncrementActiveCell()
With ActiveCell
.Value = .Value + 1
End With
End Sub

Public Sub ClearSpecificCell()
ThisWorkbook.Worksheets("Sheet1").Range("A1").Valu e = ""
End Sub

Public Sub ClearActiveCell()
ActiveCell.Value = ""
End Sub

Then, pick the ones you want to assign to command buttons.
IncrementSpecificCell always increments cell A1, regardless of what
cell happens to be active. IncrementActiveCell increments the active
cell. ClearSpecificCell always clears A1, regardless of what cell is
active. ClearActiveCell clears the active cell.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)





On Fri, 28 Aug 2009 09:27:01 -0700, Mark N
wrote:

I want to assign a macro to a command button so that it increases the value
of a cell by 1
Thanks in advance if you can help me.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Button and macro Bob[_16_] Excel Discussion (Misc queries) 4 June 12th 09 03:51 AM
Run a macro using a command button Tdahlman Excel Discussion (Misc queries) 9 March 5th 08 07:59 PM
Command Button to run a Macro Mark Allen Excel Worksheet Functions 2 June 4th 07 04:24 PM
Command Button for Macro on the Toolbar Office Junior[_2_] New Users to Excel 1 May 11th 07 12:48 PM
Run Macro from Command Button [email protected] Excel Discussion (Misc queries) 1 April 23rd 07 04:36 PM


All times are GMT +1. The time now is 01:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"