+ Reply to Thread
Results 1 to 10 of 10

Writing option button data to specific cell in a table

Hybrid View

  1. #1
    Registered User
    Join Date
    11-08-2011
    Location
    bergen county, NJ
    MS-Off Ver
    Excel 2007
    Posts
    72

    Writing option button data to specific cell in a table

    Hi all, thanks again for all your help !

    I'm attempting to merge two bits of code I have recently figured out through this forum.
    I want to add data from an option button (choice of 9 buttons in one frame) to a specific cell in a table based on the user's combobox selections...

    this is the code i'm using to get the specific cell... SCORE would be chosen by the user in the frame with all the option buttons

    Dim gradesheet As Worksheet
    Dim where1 As Range, where2 As Range
    
    Set gradesheet = ThisWorkbook.Worksheets(ComboBox3.Value)
    Set where1 = gradesheet.Range("B:B").Find(what:=ComboBox1.Value)
    Set where2 = gradesheet.Range("1:1").Find(what:=ComboBox2.Value)
    
    gradesheet.Cells(where1.Row, where2.Column) = gradesheet.SCORE.value
    this is the code for the option buttons, where "F11" would be the cell determined by the above code

    If F1opt60.Value = True Then
         Range("F11").Value = 60
    
    ElseIf F1opt65.Value = True Then
         Range("F11").Value = 65
         
    ElseIf F1opt70.Value = True Then
        Range("F11").Value = 70
        
    ElseIf F1opt75.Value = True Then
        Range("F11").Value = 75
        
    ElseIf F1opt80.Value = True Then
        Range("F11").Value = 80
        
    ElseIf F1opt85.Value = True Then
        Range("F11").Value = 85
        
    ElseIf F1opt90.Value = True Then
       Range("F11").Value = 90
       
    ElseIf F1opt95.Value = True Then
      Range("F11").Value = 95
      
    ElseIf F1opt100.Value = True Then
        Range("F11").Value = 100
    End If
    End Sub
    i can't figure out how to nest this...

    any help would be sooo much appreciated !

    thanks!
    -rob
    Last edited by teacher_rob; 11-11-2011 at 03:09 PM.

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Writing option button data to specific cell in a table

    
    sub something
    
    Dim gradesheet As Worksheet
    Dim where1 As Range, where2 As Range
    
    Set gradesheet = ThisWorkbook.Worksheets(ComboBox3.Value)
    Set where1 = gradesheet.Range("B:B").Find(what:=ComboBox1.Value)
    Set where2 = gradesheet.Range("1:1").Find(what:=ComboBox2.Value)
    
    If F1opt60.Value = True Then
         gradesheet.cells(where1.row,where2,column).Value = 60 ' same structure down
    
    ElseIf F1opt65.Value = True Then
         Range("F11").Value = 65
         
    ElseIf F1opt70.Value = True Then
        Range("F11").Value = 70
        
    ElseIf F1opt75.Value = True Then
        Range("F11").Value = 75
        
    ElseIf F1opt80.Value = True Then
        Range("F11").Value = 80
        
    ElseIf F1opt85.Value = True Then
        Range("F11").Value = 85
        
    ElseIf F1opt90.Value = True Then
       Range("F11").Value = 90
       
    ElseIf F1opt95.Value = True Then
      Range("F11").Value = 95
      
    ElseIf F1opt100.Value = True Then
        Range("F11").Value = 100
    End If
    
    end sub

  3. #3
    Registered User
    Join Date
    11-08-2011
    Location
    bergen county, NJ
    MS-Off Ver
    Excel 2007
    Posts
    72

    Re: Writing option button data to specific cell in a table

    I'm trying this code, and i'm getting "obvject variable or with block variable not set".

    not sure what that means

  4. #4
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Writing option button data to specific cell in a table

    If the optionbutton are on a frame, then reference it

    
    If FrameReference.F1opt60.Value = True Then
         gradesheet.cells(where1.row,where2,column).Value = 60 ' same structure down
    If its on a userform then

    If UserForm1.F1opt60.Value = True Then
         gradesheet.cells(where1.row,where2,column).Value = 60 ' same structure down
    Last edited by Steffen Thomsen; 11-11-2011 at 11:31 AM.

  5. #5
    Registered User
    Join Date
    11-08-2011
    Location
    bergen county, NJ
    MS-Off Ver
    Excel 2007
    Posts
    72

    Re: Writing option button data to specific cell in a table

    the option buttons are in a frame. i updated the code with that in mind, but still the same error

  6. #6
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Writing option button data to specific cell in a table

    Wich line of code gives the error?

    Could you post an example workbook and i'll have a look at it!

  7. #7
    Registered User
    Join Date
    11-08-2011
    Location
    bergen county, NJ
    MS-Off Ver
    Excel 2007
    Posts
    72

    Re: Writing option button data to specific cell in a table

    " If Frame1.F1opt60.Value = True Then " this is where the debugger says something is wrong...
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    11-08-2011
    Location
    bergen county, NJ
    MS-Off Ver
    Excel 2007
    Posts
    72

    Re: Writing option button data to specific cell in a table

    the code works when i'm entering in data from the text box... i'm able to select either sheet, and then fill in the appropriate cell with the info obtained from the comboboxes... when i try it with the option buttons it gets tripped up (as do I )

  9. #9
    Registered User
    Join Date
    11-08-2011
    Location
    bergen county, NJ
    MS-Off Ver
    Excel 2007
    Posts
    72

    Re: Writing option button data to specific cell in a table

    ok, it's kind of working now... i realized i had cut and pasted some code from another attempt, and neglected to change the names... so the code pasted here is allowing me to enter the score corresponding to the correct option button, however, it's not letting me post to "student3" sheet... when student 3 is selected it is putting the data in "student1" sheet

    Private Sub CommandButton1_Click()
    Dim gradesheet As Worksheet
    Dim where1 As Range, where2 As Range
    
    Set gradesheet = ThisWorkbook.Worksheets(ComboBox3.Value)
    
    Set where1 = gradesheet.Range("A:A").Find(what:=ComboBox1.Value)
    Set where2 = gradesheet.Range("1:1").Find(what:=ComboBox2.Value)
    
    'gradesheet.Cells(where1.Row, where2.Column) = TextBox1.Value
    
    If Frame1.opt60.Value = True Then
         gradesheet.Cells(where1.Row, where2.Column) = 60
    
    ElseIf Frame1.opt65.Value = True Then
         gradesheet.Cells(where1.Row, where2.Column).Value = 65
         
    ElseIf Frame1.opt70.Value = True Then
       gradesheet.Cells(where1.Row, where2.Column).Value = 70
        
    ElseIf Frame1.opt75.Value = True Then
        gradesheet.Cells(where1.Row, where2.Column).Value = 75
        
    ElseIf Frame1.opt80.Value = True Then
      gradesheet.Cells(where1.Row, where2.Column).Value = 80
        
    ElseIf Frame1.opt85.Value = True Then
       gradesheet.Cells(where1.Row, where2.Column).Value = 85
        
    ElseIf Frame1.opt90.Value = True Then
       gradesheet.Cells(where1.Row, where2.Column).Value = 90
       
    ElseIf Frame1.opt95.Value = True Then
      gradesheet.Cells(where1.Row, where2.Column).Value = 95
      
    ElseIf Frame1.opt100.Value = True Then
        gradesheet.Cells(where1.Row, where2.Column).Value = 100
    End If
    
    
    
    End Sub
    
    
    
    Private Sub UserForm_Initialize()
    
    Dim ws As Worksheet
    For Each ws In Worksheets
        ComboBox3.AddItem ws.Name
        Next ws
        
    End Sub

  10. #10
    Registered User
    Join Date
    11-08-2011
    Location
    bergen county, NJ
    MS-Off Ver
    Excel 2007
    Posts
    72

    Re: Writing option button data to specific cell in a table

    i think i spoke toooo soon. it is doing exactly as i am asking it to do !!!

    thank you guys so much ! going to mark this is solved.

    in a few hours i will be back with another question about another little bit of the big userform i'm attempting to put together !

    -rob

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1