Option Button Macro

aja4481

New Member
Joined
Mar 15, 2011
Messages
26
Hello all. i'm trying to set up a macro where if someone chooses the option button, Column B is subtracted from Column A. But if the button is unchecked, Column A is the whole number.

if anyone can help me with how I can set this up I would appreciate it.

Thank you!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
The following will subtract column B from column A and put the value into column C.

Try it on a test page just in case, better safe than sorry.


Code:
Private Sub Optionbutton1_click()
 
Range("B2").Select
Cells(65535, ActiveCell.Column).Select
   Range(Selection, Selection.End(xlUp)).Select
   ActiveCell.Select
   ActiveCell.Offset(0, 1).Select
Set BottomCell = ActiveCell
    Set TopCell = Cells(1, ActiveCell.Column)
      Range(TopCell, BottomCell).Select
Dim Cell As Range
For Each Cell In Selection
  If Cell.Value = "" Then
    ActiveCell.FormulaR1C1 = "=RC[-1]-RC[-2]"
   ActiveCell.Offset(1, 0).Select
  End If
Next Cell
Me.Optionbutton1.Value = False
End Sub
 
Upvote 0
thank you very much! it works great. is it possible to have either the amount only included or excluded just from Column A and not put the revised value in colmn C?

So checked Column A = A-B; Unchecked A remins the same
 
Upvote 0
Try the following, it worked on my version.


Code:
Private Sub Optionbutton1_click()
Me.Optionbutton1.Value = False
 
Range("B2").Select
Cells(65535, ActiveCell.Column).Select
   Range(Selection, Selection.End(xlUp)).Select
   ActiveCell.Select
   ActiveCell.Offset(0, -1).Select
Set BottomCell = ActiveCell
    Set TopCell = Cells(1, ActiveCell.Column)
      Range(TopCell, BottomCell).Select
 
Dim Cell As Range
For Each Cell In Selection
  If Cell.Value <> "" Then
    ActiveCell.FormulaR1C1 = ActiveCell.Value - ActiveCell.Offset(0, 1)
   ActiveCell.Offset(1, 0).Select
  End If
   '
Next Cell
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,277
Members
452,902
Latest member
Knuddeluff

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