LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Call subroutine based on combination of Option buttons (two groups)

Goal: Calculate average precipitation based on Month and Year.
Worksheets: "2016" and "2017"
Option Buttons: OptionButton1, OptionButton2, OptionButton3, OptionButton4,
Form: UserForm1

I have two groups of Option buttons on UserForm1 -- one group under "Month" (Frame1) and one group under "Year (Frame2).

I'd like to call a subroutine based on the combination of buttons selected.

For example, if a user selects January and selects 2016 (and then clicks "OK"), subroutine "January2016" is called. From there, I'd like to 1) activate sheet "2016" and 2) calculate the average precipitation for January and 3) put the value in the appropriate cell, in this case cell C9. Same for January 2017, etc.

Here's what "Form1" looks like. (The zeros are option buttons.)

Month Year [OK]
O January O 2016 [Cancel]
O February O 2017

Here's what the sheet, "2016" looks like. (Sheet "2017" is similar.)
-A- -B- -C-
1 Month Date Precip
2 Jan 01/01/17 5
3 Jan 01/15/17 10
4 Jan 01/31/17 15
5 Feb 02/01/17 20
6 Feb 02/15/17 30
7 Feb 02/28/17 40
8 ===============================
9 Jan AvgPrecip _____
10 Feb AvgPrecip _____

Here's my code. (It works so far but I haven't figured out how to go to the appropriate sheet and calculate the average rainfall.)

Sub CommandButton1_Click()
If Me.OptionButton1.Value = True And Me.OptionButton3.Value = True Then Call January2016

If Me.OptionButton1.Value = True And Me.OptionButton4.Value = True Then Call January2017

If Me.OptionButton2.Value = True And Me.OptionButton3.Value = True Then Call February2016

If Me.OptionButton2.Value = True And Me.OptionButton4.Value = True Then Call February2017
End Sub

Sub CommandButton2_Click()
Unload UserForm1
End Sub

Sub January2016()
MsgBox "January 2016"
' Go to Sheet 2016 and calculate average precipitation for January
End Sub

Sub January2017()
MsgBox "January 2017"
' Go to Sheet 2017 and calculate average precipitation for January
End Sub

Sub February2016()
MsgBox "February 2016"
' Go to Sheet 2017 and calculate average precipitation for January
End Sub

Sub February2017()
MsgBox "February 2017"
' Go to Sheet 2017 and calculate average precipitation for February
End Sub

Sub ClearOptionButtons()
UserForm1.OptionButton1.Value = False
UserForm1.OptionButton2.Value = False
UserForm1.OptionButton3.Value = False
UserForm1.OptionButton4.Value = False
End Sub

 
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
Option buttons in two levels groups Jac Tremblay[_4_] Excel Programming 1 October 9th 08 04:38 AM
Accessing groups of option buttons Brotherwarren Excel Programming 4 February 17th 08 08:31 PM
Groups in Option buttons Greg B[_12_] Excel Programming 15 January 24th 08 06:09 PM
Two Groups of Option Buttons on Worksheet Jim May Excel Discussion (Misc queries) 0 June 24th 06 09:34 PM
Option Buttons - groups Ciara Excel Discussion (Misc queries) 4 May 18th 05 05:41 PM


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