Consulting

Results 1 to 9 of 9

Thread: OptionButton LinkedCell trouble

  1. #1

    OptionButton LinkedCell trouble

    Trying to link OptionBut's to range B3:B14 3 but's on each
    But when i run this code, all Link's goes to B14 !!!
    What the heck is going on :-) pls. help

    Sub AddOptionButton()
    ActiveSheet.DrawingObjects.Delete
    For Each c In Range("B3:B14")
        c.Select
            With ActiveSheet.OptionButtons.Add(Selection.Left, Selection.Top, Selection.Width, Selection.Height)
                .LinkedCell = "Ark1!" & Cells(c.Row, "E").Address
                .Name = "knap" & c.Row * 3 - 8
                .Caption = "100%"
            End With
    
        c.Offset(0, 1).Select
             With ActiveSheet.OptionButtons.Add(Selection.Left, Selection.Top, Selection.Width, Selection.Height)
               .Name = "knap" & c.Row * 3 - 7
               .Caption = "10%"
          End With
    
       c.Offset(0, 2).Select
             With ActiveSheet.OptionButtons.Add(Selection.Left, Selection.Top, Selection.Width, Selection.Height)
                 .Name = "knap" & c.Row * 3 - 6
                 .Caption = "0%"
          End With
    Next
    End Sub
    Last edited by SamT; 03-10-2018 at 01:05 PM.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    :
    Try
     .LinkedCell = "Ark1!E" & C.Row
    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
    nope that didn't help ;-)

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    May be
    Str ="Ark1!E" & C.Row
    .LinkedCell = Str
    Excel 2002 Help File:
    Example

    This example adds a check box to worksheet one and links the check box value to cell A1.
    With Worksheets(1)
        Set cb = .Shapes.AddFormControl(xlCheckBox, 10, 10, 100, 10)
        cb.ControlFormat.LinkedCell = "A1"
    End With
    Note that nowhere in my help files does it indicate that any sort of optionbutton has a "Linked Cell," But viewing the Properties of one on an Excel Sheet does show the LinkedCell Property
    Last edited by SamT; 03-10-2018 at 02:48 PM.
    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

  5. #5
    nope that didn't help

  6. #6
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Try using OLE Objects

        ActiveSheet.OLEObjects.Add(ClassType:="Forms.OptionButton.1", Link:=False, _
            DisplayAsIcon:=False, Left:=270, Top:=84, Width:=108, Height:=19.5).
    Last edited by SamT; 03-10-2018 at 04:11 PM.
    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

  7. #7
    can you pls. paste complete code, i got errors when run

  8. #8
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I just recorded a Macro to see how to insert OLE objects with VBA. That is the complete code I recorded

    Using Controls on worksheets is hard! It's all really old Excel 4 legacy code.

    If It were me, I would just make a table with the Percentages in it, then Use the Sheet Before Doubleclick Event Sub select what I needed based on the Target Address. Simple, straight forward logic.

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Intersect(Target, Range("B3:D14") is nothing then Exit sub
    Cancel = True
    Intersect(Target.Row, Range("B3:D14")).Font.Bold = False
    Target.Font.Bold = True
    
    Sheets("Arc1").Cells(Target.Row, "E") = Target
    
    End Sub
    Last edited by SamT; 03-10-2018 at 04:33 PM.
    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

  9. #9
    ok SamT ill try that. thanks anyway ;.)

Posting Permissions

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