Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Increment Cell Value by 1

I have a fairly simple operation I am trying to implement.

I have a command button called "Screen" in worksheet "Sheet1" of Workbook
"Book1". When I click it, I want the value in cell C2 to increase by one
(e.g., if C2 = 3, I want it to automatically increase to 4 when I click
Screen.

Can anyone provide code for this operation?

Thanks,
Bob
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Increment Cell Value by 1

Assign your button to:

Sub marine()
With Workbooks("Book1.xls").Sheets("Sheet1").Range("C2" )
.Value = .Value + 1
End With
End Sub

--
Gary's Student
gsnu200703


"bob" wrote:

I have a fairly simple operation I am trying to implement.

I have a command button called "Screen" in worksheet "Sheet1" of Workbook
"Book1". When I click it, I want the value in cell C2 to increase by one
(e.g., if C2 = 3, I want it to automatically increase to 4 when I click
Screen.

Can anyone provide code for this operation?

Thanks,
Bob

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Increment Cell Value by 1

From Control Toobox toolbar? If yes, right-click, view code, then:
Private Sub CommandButton1_Click()
Range("C2") = Range("C2") + 1
End Sub

Hth,
Merjet

  #4   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Increment Cell Value by 1

I don't have a programming background, so I need to ask, How do I assign the
button to this code?

Thanks very much,
Bob

"Gary''s Student" wrote:

Assign your button to:

Sub marine()
With Workbooks("Book1.xls").Sheets("Sheet1").Range("C2" )
.Value = .Value + 1
End With
End Sub

--
Gary's Student
gsnu200703


"bob" wrote:

I have a fairly simple operation I am trying to implement.

I have a command button called "Screen" in worksheet "Sheet1" of Workbook
"Book1". When I click it, I want the value in cell C2 to increase by one
(e.g., if C2 = 3, I want it to automatically increase to 4 when I click
Screen.

Can anyone provide code for this operation?

Thanks,
Bob

  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Increment Cell Value by 1

Sorry, but I am still having trouble. From the Control Toolbox toolbar, I
selected Button and created a button called "CommandButton1". I right-clicked
and selected View Code. I pasted the code you provided, saved and returned to
Excel. But when I go to click the button, the button becomes selected,
resizing handles appear and the value in the C2 does not change. It appears
as if the button is not associated with the code.

What am I doing wrong?

Thanks,
Bob

"merjet" wrote:

From Control Toobox toolbar? If yes, right-click, view code, then:

Private Sub CommandButton1_Click()
Range("C2") = Range("C2") + 1
End Sub

Hth,
Merjet




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Increment Cell Value by 1

1. put the code in a standard module:

1.a. from Excel ALT-F11 to get the VBE window
1.b. touch ALT-I
ALT-M to get a fresh module
1.c. paste the stuff in
1.d. close the VBE window

2. in Excel make a button using the forms tools
3. right-click the button and assign the macro.
--
Gary's Student
gsnu200703


"bob" wrote:

I don't have a programming background, so I need to ask, How do I assign the
button to this code?

Thanks very much,
Bob

"Gary''s Student" wrote:

Assign your button to:

Sub marine()
With Workbooks("Book1.xls").Sheets("Sheet1").Range("C2" )
.Value = .Value + 1
End With
End Sub

--
Gary's Student
gsnu200703


"bob" wrote:

I have a fairly simple operation I am trying to implement.

I have a command button called "Screen" in worksheet "Sheet1" of Workbook
"Book1". When I click it, I want the value in cell C2 to increase by one
(e.g., if C2 = 3, I want it to automatically increase to 4 when I click
Screen.

Can anyone provide code for this operation?

Thanks,
Bob

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Increment Cell Value by 1

See that upper left icon (including a triangle) on the Control Toolbox
toolbar?
That toggles Design Mode. In Design Mode, you add/modify code. Not in
Design Mode, the code is used when you click the CommandButton.

Hth,
Merjet

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Increment Cell Value by 1

Bob

You are still in "Design Mode"

Bring down the Control Toolbox bar and de-select design mode(top left icon)


Gord Dibben MS Excel MVP

On Mon, 29 Jan 2007 13:06:00 -0800, bob wrote:

Sorry, but I am still having trouble. From the Control Toolbox toolbar, I
selected Button and created a button called "CommandButton1". I right-clicked
and selected View Code. I pasted the code you provided, saved and returned to
Excel. But when I go to click the button, the button becomes selected,
resizing handles appear and the value in the C2 does not change. It appears
as if the button is not associated with the code.

What am I doing wrong?

Thanks,
Bob

"merjet" wrote:

From Control Toobox toolbar? If yes, right-click, view code, then:

Private Sub CommandButton1_Click()
Range("C2") = Range("C2") + 1
End Sub

Hth,
Merjet



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
How do I get a cell to increment during printing Brian Excel Discussion (Misc queries) 4 June 17th 09 07:55 PM
Increment cell reference Larry Kahm Excel Discussion (Misc queries) 1 April 8th 08 01:40 AM
Increment cell prefix Brettjg Excel Discussion (Misc queries) 2 April 27th 07 09:08 AM
check cell val, increment val DJS Excel Worksheet Functions 0 January 30th 06 10:29 PM
Increment/Increment letter in alphabetical order Neil Goldwasser Excel Programming 3 January 25th 06 09:07 AM


All times are GMT +1. The time now is 09:48 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"