Consulting

Results 1 to 5 of 5

Thread: Excel Optionbutton Calculations

  1. #1
    VBAX Regular
    Joined
    Apr 2018
    Posts
    50
    Location

    Excel Optionbutton Calculations


    I did this before for word. All I'm trying to do is get the optionbuttons to calculate.

    i'm using ms excel 2010. I have 4 optionbuttons for each section. I'm trying to get the Score = selected value * 10 for 2 sections. i need to get the sum of 2 results for grandtotal for both and scores.
    im NOT having any success at it.
    i wont mind if someone use another number besides 10 for examples and steps.

    Private Sub OptionButton_1_0_Click()
      If OptionButton_1_0 Then
      Selection.Range(A6:A9).(B9)Range.Text = "0"
      End If
    End Sub
    Private Sub OptionButton_1_1_Click()
      If OptionButton_1_1 Then
       Selection.Range(A6:A9).(B8)Range.Text = "10"
      End If
    End Sub
    Private Sub OptionButton_1_2_Click()
      If OptionButton_1_2 Then
        Selection.Range(A6:A9).(B7)Range.Text = "20"
      End If
    End Sub
    Private Sub OptionButton_1_3_Click()
      If OptionButton_1_3 Then
        Selection.Range(A6:A9).(B6)Range.Text = "30"
      End If
    End Sub
    Private Sub OptionButton_1_0_Click()
      If OptionButton_2_0 Then
      Selection.Range(A11:A14).(B14)Range.Text = "0"
      End If
    End Sub
    Private Sub OptionButton_1_1_Click()
      If OptionButton_2_1 Then
       Selection.Range(A11:A14).(B13)Range.Text = "10"
      End If
    End Sub
    Private Sub OptionButton_1_2_Click()
      If OptionButton_2_2 Then
        Selection.Range(A11:A14).(B12)Range.Text = "20"
      End If
    End Sub
    Private Sub OptionButton_1_3_Click()
      If OptionButton_2_3 Then
        Selection.Range(A11:A14).(B11)Range.Text = "30"
      End If
    End Sub
    Attached Images Attached Images
    Last edited by SamT; 04-18-2018 at 12:33 PM.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I suspect this is a Word code structure
    Selection.Range(A6:A9).(B9)Range.Text
    In Excel, for Range B9, use:
    ActiveSheet.Range("B9") = 10
    The Use of "ActiveSheet" is discouraged, since the Active sheet can easily change. You can use Sheets("SheetName") to specify the sheet, or you can Set a variable to the sheet and use the Variable
    Sheets("SheetName").Range("B9") = 10
    Dim Sht as Worksheet 'Or as Object
    Set Sht = ActiveSheet
    'Or
    Set Sht = Sheets("SheetName")
    
    Sht.Range("B9") = 10
    For code that is on/in that Sheet's Code Page, you do not have to specify the Range's Parent sheet
     Range("B9") = 10
    Note that Range Addresses are Strings and must be inside doublequote marks. Cells addresses are two numbers Cells(9, 2) = 10 or a Row number and a Column Letter(s) Cells(9, "B") = 10

    Cells are used when convenient, and, are the best way to use cells in a Loop
    Dim i As Long
    For i = 1 to 10
    Cells(1, i + 1) = i
    Cells( i + 1, "A") = i * 10
    Next
    Cells are most often use when finding the last used Cell in a Row or Column
    Dim LR As Long 'For Last row
    LR = Cells(Rows.Count, "B").End(xlUp).Row
    
    Dim NR As Long 'For Next Row
    NR = Cells(Rows.Count, "B").End(xlUp).Row + 1
    
    Dim LC As Long 'For Last Column
    LC = Cells(1, Columns.Count).End(xlToLeft).Column
    "End" is like the Keyborad Arrow keys,with the Parameter being the direction (XlUp), (xlDown), (xlToLeft), and (xlToRight)

    Note: always Declare Row and Column number Variables as Longs.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    1. Didn't understand the requirement in the Word forum either

    2. Here's an example workbook using Excel concepts

    If I understand rightly ... There are two groups of 4 option buttons, with only a single OB selectable in each group. Each OB selects a number and puts it in a cell

    I used Form Controls (not ActiveX) to put 2 Frames and 4 OB in each frame.

    Each OB has a macro


    Option Explicit
    Sub OB1_0_Click()
        Range("A6").Value = 0
    End Sub
    Sub OB1_1_Click()
        Range("A6").Value = 10
    End Sub
    Sub OB1_2_Click()
        Range("A6").Value = 20
    End Sub
    Sub OB1_3_Click()
        Range("A6").Value = 30
    End Sub
    Sub OB2_0_Click()
        Range("A11").Value = 0
    End Sub
    Sub OB2_1_Click()
        Range("A11").Value = 10
    End Sub
    Sub OB2_2_Click()
        Range("A11").Value = 20
    End Sub
    Sub OB2_3_Click()
        Range("A11").Value = 30
    End Sub
    Maybe this example will help
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Regular
    Joined
    Apr 2018
    Posts
    50
    Location
    Quote Originally Posted by Paul_Hossler View Post
    1. Didn't understand the requirement in the Word forum either

    2. Here's an example workbook using Excel concepts

    If I understand rightly ... There are two groups of 4 option buttons, with only a single OB selectable in each group. Each OB selects a number and puts it in a cell

    I used Form Controls (not ActiveX) to put 2 Frames and 4 OB in each frame.

    Each OB has a macro


    Option Explicit
    Sub OB1_0_Click()
        Range("A6").Value = 0
    End Sub
    Sub OB1_1_Click()
        Range("A6").Value = 10
    End Sub
    Sub OB1_2_Click()
        Range("A6").Value = 20
    End Sub
    Sub OB1_3_Click()
        Range("A6").Value = 30
    End Sub
    Sub OB2_0_Click()
        Range("A11").Value = 0
    End Sub
    Sub OB2_1_Click()
        Range("A11").Value = 10
    End Sub
    Sub OB2_2_Click()
        Range("A11").Value = 20
    End Sub
    Sub OB2_3_Click()
        Range("A11").Value = 30
    End Sub
    Maybe this example will help

    you on the money Paul.

    everything got to be in the order in the attachment i had originally posted like this. where the 10s just still there and look good lol. just got the have to scores at the top and the grandtotal at the bottom
    Attached Images Attached Images

  5. #5
    VBAX Regular
    Joined
    Apr 2018
    Posts
    50
    Location
    NEVERMIND I GOT IT!!!!!!!! THANKS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •