Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro adds 1 to Cell in excel


Im just learning vba and this is probably so simple its embarassing.

I have 2 q's and any answer would be greatly appreciated.


I have a form, with a frame with 2 option boxes.

If the first option box is picked the macro will add 1 to the value in
the activecell in my worksheet

If the second box is selected, it will subtract 1

thanks


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Macro adds 1 to Cell in excel

Try something like


Private Sub OptionButton1_Click()
ActiveCell.Value = ActiveCell.Value + 1
End Sub

Private Sub OptionButton2_Click()
ActiveCell.Value = ActiveCell.Value - 1
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Xispo" wrote in message
...

Im just learning vba and this is probably so simple its embarassing.

I have 2 q's and any answer would be greatly appreciated.


I have a form, with a frame with 2 option boxes.

If the first option box is picked the macro will add 1 to the value in
the activecell in my worksheet

If the second box is selected, it will subtract 1

thanks


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Macro adds 1 to Cell in excel

How do you generalise that to a large number of option buttons?

Say you had 20 option buttons, it would be much better to pick that up with
one routine that deals with any optionbutton being clicked. How do you do
that?

Thanks

Geoff



"Chip Pearson" wrote in message
...
Try something like


Private Sub OptionButton1_Click()
ActiveCell.Value = ActiveCell.Value + 1
End Sub

Private Sub OptionButton2_Click()
ActiveCell.Value = ActiveCell.Value - 1
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Xispo" wrote in message
...

Im just learning vba and this is probably so simple its embarassing.

I have 2 q's and any answer would be greatly appreciated.


I have a form, with a frame with 2 option boxes.

If the first option box is picked the macro will add 1 to the value in
the activecell in my worksheet

If the second box is selected, it will subtract 1

thanks


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro adds 1 to Cell in excel

If your adding one and subtracting one, what would you do for other option
buttons?

However, if you want to handle the events for multiple controls with one
routine you can use the technique documented by John Walkenbach:

http://j-walk.com/ss/excel/tips/tip44.htm
Handle Multiple UserForm Buttons With One Subroutine

The technique is generic and can be used with all of the msforms controls,
either on a userform or on a worksheet. You can not trap events which are
provided by the container (control on userform and oleobject on worksheet)
such as the exit event on a userform.

--
Regards,
Tom Ogilvy


"GB" wrote in message
...
How do you generalise that to a large number of option buttons?

Say you had 20 option buttons, it would be much better to pick that up

with
one routine that deals with any optionbutton being clicked. How do you do
that?

Thanks

Geoff



"Chip Pearson" wrote in message
...
Try something like


Private Sub OptionButton1_Click()
ActiveCell.Value = ActiveCell.Value + 1
End Sub

Private Sub OptionButton2_Click()
ActiveCell.Value = ActiveCell.Value - 1
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Xispo" wrote in message
...

Im just learning vba and this is probably so simple its embarassing.

I have 2 q's and any answer would be greatly appreciated.


I have a form, with a frame with 2 option boxes.

If the first option box is picked the macro will add 1 to the value in
the activecell in my worksheet

If the second box is selected, it will subtract 1

thanks


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from

http://www.ExcelForum.com/







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Macro adds 1 to Cell in excel


"Tom Ogilvy" wrote in message
...
If your adding one and subtracting one, what would you do for other option
buttons?

You might have them add other amounts to the active cell value:

Button1 = add 1
Button2 = add 2

and so on.

So if you could find the x of OptionButtonx then you could handle all the
code with just one line:
ActiveCell.Value = ActiveCell.Value + x

I'll have a look at John Walkenbach's tip, but it sounds a bit swanky, with
a class module.

Thanks

Geoff





However, if you want to handle the events for multiple controls with one
routine you can use the technique documented by John Walkenbach:

http://j-walk.com/ss/excel/tips/tip44.htm
Handle Multiple UserForm Buttons With One Subroutine

The technique is generic and can be used with all of the msforms controls,
either on a userform or on a worksheet. You can not trap events which are
provided by the container (control on userform and oleobject on worksheet)
such as the exit event on a userform.

--
Regards,
Tom Ogilvy


"GB" wrote in message
...
How do you generalise that to a large number of option buttons?

Say you had 20 option buttons, it would be much better to pick that up

with
one routine that deals with any optionbutton being clicked. How do you

do
that?

Thanks

Geoff



"Chip Pearson" wrote in message
...
Try something like


Private Sub OptionButton1_Click()
ActiveCell.Value = ActiveCell.Value + 1
End Sub

Private Sub OptionButton2_Click()
ActiveCell.Value = ActiveCell.Value - 1
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Xispo" wrote in message
...

Im just learning vba and this is probably so simple its embarassing.

I have 2 q's and any answer would be greatly appreciated.


I have a form, with a frame with 2 option boxes.

If the first option box is picked the macro will add 1 to the value

in
the activecell in my worksheet

If the second box is selected, it will subtract 1

thanks


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from

http://www.ExcelForum.com/









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
macro that adds formula to replace text Lawribird Excel Worksheet Functions 4 July 3rd 09 09:50 PM
Formulas change when macro adds new column Sandra Excel Worksheet Functions 3 January 23rd 09 11:25 PM
Creating a button in excel that adds one to a cell artie_p Excel Discussion (Misc queries) 2 August 28th 07 01:12 AM
Is there a macro which adds selected/highlighted cells? Ed Excel Worksheet Functions 2 September 28th 05 01:36 PM
Macro which adds new spreadsheets matraxus Excel Programming 0 August 25th 03 10:52 AM


All times are GMT +1. The time now is 03:22 AM.

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"