+ Reply to Thread
Results 1 to 7 of 7

Fastest way to fill in values on a form

  1. #1
    Forum Contributor
    Join Date
    09-02-2005
    Posts
    146

    Fastest way to fill in values on a form

    I have 15 groups of 3 optionbuttons that need to have previously selected values included. They all have similar names and it seems like I should be able to use a looping macro to call up each value, but I'm not allowed to use the form of:

    buttonname = cell value + loop
    formname.buttonname.value = true/false

    Is it possible to do what I want to do, or am I stuck manually naming each button and giving it a value?

    For i = 1 To 15
    v1 = sheets("admin").Cells(80 + i, 3).Value + "NI"
    v2 = sheets("admin").Cells(80 + i, 3).Value + "I"
    v3 = sheets("admin").Cells(80 + i, 3).Value + "E"
    If Cells(80 + i, 2) = "Excluded" Then
    Options.v1.Value = False
    Options.v2.Value = False
    Options.v3.Value = True
    ElseIf Cells(80 + i, 2) = "Included" Then
    Options.v1.Value = False
    Options.v2.Value = True
    Options.v3.Value = False
    Else
    Options.v1.Value = True
    Options.v2.Value = False
    Options.v3.Value = False
    End If
    Next

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    I can't tell exactly what your code is trying to do, but if you had option buttons named "opt1" through "opt15", you could do this in the userform module:
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    09-02-2005
    Posts
    146
    Yep, that was the trick. This works just as I needed it to,

    For i = 1 To 15
    v1 = Sheets("admin").Cells(80 + i, 3).Value + "NI"
    v2 = Sheets("admin").Cells(80 + i, 3).Value + "I"
    v3 = Sheets("admin").Cells(80 + i, 3).Value + "E"
    If Sheets("admin").Cells(80 + i, 2).Value = "Excluded" Then
    Options.Controls(v1).Value = False
    Options.Controls(v2).Value = False
    Options.Controls(v3).Value = True
    ElseIf Sheets("admin").Cells(80 + i, 2).Value = "Included" Then
    Options.Controls(v1).Value = False
    Options.Controls(v2).Value = True
    Options.Controls(v3).Value = False
    Else
    Options.Controls(v1).Value = True
    Options.Controls(v2).Value = False
    Options.Controls(v3).Value = False
    End If
    Next

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    As option buttons, you only need to set one to True, and the others in the same frame will automatically switch to False -- that's what option buttons do ...

  5. #5
    Forum Contributor
    Join Date
    06-27-2006
    Posts
    310
    Quote Originally Posted by wilro85
    Yep, that was the trick. This works just as I needed it to,
    here I fixed it for you

    Quote Originally Posted by wilro85
    Yep, that was the trick. This works just as I needed it to,
    Thanks for the help

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Quote Originally Posted by SuitedAces
    here I fixed it for you
    I see what you mean, another one to add to the Ignore List!
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Wilro, please take SuitedAces gentle point ...

+ 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