+ Reply to Thread
Results 1 to 6 of 6

Trying to place radio buttons using vba in a form. With a for next loop

  1. #1
    Registered User
    Join Date
    03-24-2013
    Location
    NY
    MS-Off Ver
    Excel 2013
    Posts
    7

    Trying to place radio buttons using vba in a form. With a for next loop

    What I am trying to do is make a custom form based on values from the worksheet. I am looking up the values and using a for next loop to place the buttons on the form. I am also pulling the information for the buttons caption from the worksheet. I can get it to almost work until I try to use a variable. The problem is in this part of the code. I think.UserForm1.Controls.Add("Forms.inputbutton", "radioname", True)
    Maybe I need to declare inputbutton as something other than variant. I am getting the error (Invalid string class ) Thanks for the help. I will post my code when I figure out how to do that.

  2. #2
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Trying to place radio buttons using vba in a form. With a for next loop

    What happens if you try
    Please Login or Register  to view this content.
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Trying to place radio buttons using vba in a form. With a for next loop

    This code will add an option button called opt1.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    03-24-2013
    Location
    NY
    MS-Off Ver
    Excel 2013
    Posts
    7

    Re: Trying to place radio buttons using vba in a form. With a for next loop

    This is my code. I am trying to use a variable that increases on each loop that will get the next value from the worksheet. I hope that I put the code in the correct way.
    Please Login or Register  to view this content.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Trying to place radio buttons using vba in a form. With a for next loop

    This will add an option buttons each with a caption from column A on start options.
    Please Login or Register  to view this content.
    It places the option buttons down the left of the form with no space between.

  6. #6
    Registered User
    Join Date
    03-24-2013
    Location
    NY
    MS-Off Ver
    Excel 2013
    Posts
    7

    Re: Trying to place radio buttons using vba in a form. With a for next loop

    Thank You. It worked great. I was wondering if you could give me a little tutorial on how this works. It looks like the main part is DIM OPT AS MSFORMS.OPTIONBUTTON. BUt I am a little confused on what is going on behind the scenes. I would like a better understanding because this is just the start of my project and I will be needing to pull all sorts of data from different sheets based on what the user enters. via-check boxes, input fields and buttons. Thanks again.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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