+ Reply to Thread
Results 1 to 5 of 5

Loop through userform frame controls

Hybrid View

  1. #1
    Registered User
    Join Date
    10-01-2012
    Location
    molde
    MS-Off Ver
    Excel 2010
    Posts
    49

    Loop through userform frame controls

    Hi
    I have a userform with multiple optionbuttons in a frame. When i launch the userform i want the value og the optionbox that has the same caption as cell A2 in worksheet "Enhet", to be TRUE. Hope I explained it OK. I have tried the code below. But I have never tried this before, så it may be way of...

    Sub enhet_valg()
    Dim x As Control
    
    For Each x In UserForm1.Frame1.Controls
    If Worksheets("Enhet").Range("A2").Text = x.Caption Then
    x.Value = True
    End If
    Next x
    
    End Sub

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Loop through userform frame controls

    depends but basically
    Sub enhet_valg()
    Dim x As Control
    
    For Each x In UserForm1("Frame1").Controls
    If Worksheets("Enhet").Range("A2").Text = x.Caption Then
    x.Value = True
    End If
    Next x
    
    End Sub
    expanded

      Dim x As Control
    
        For Each x In UserForm2("Frame1").Controls
            If TypeName(x) Like "OptionButton" Then
                If Worksheets("Enhet").Range("A2").Text = x.Caption Then
                    x.Value = True
                End If
            End If
        Next x
    Last edited by pike; 05-12-2016 at 03:55 AM.
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Loop through userform frame controls

    or
     Dim x As Control
    
        For Each x In UserForm2("Frame1").Controls
            Debug.Print TypeName(x)
            If TypeName(x) Like "CheckBox" Then
                If Range("A2").Text = x.Caption then
                 x.Value =true
                End If
            End If
        Next x

  4. #4
    Registered User
    Join Date
    10-01-2012
    Location
    molde
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: Loop through userform frame controls

    Quote Originally Posted by pike View Post
    or
     Dim x As Control
    
        For Each x In UserForm2("Frame1").Controls
            Debug.Print TypeName(x)
            If TypeName(x) Like "CheckBox" Then
                If Range("A2").Text = x.Caption then
                 x.Value =true
                End If
            End If
        Next x
    Perfect! Thank you so much!!

  5. #5
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Loop through userform frame controls

    Hello
    you can check the checkbox with Boolean value to remove one if statement from the sub routine
    eg...
        For Each x In UserForm2("Frame1").Controls
            If TypeName(x) Like "CheckBox" Then
                x.Value =Worksheets("Enhet").Range("A2").Text = x.Caption
            End If

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Looping through controls by frame on userform (frame within a frame)
    By njs27 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-27-2015, 10:21 AM
  2. [SOLVED] adapt userform loop using control name containing variable for worksheet activex controls
    By bmeister in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-22-2014, 02:45 PM
  3. [SOLVED] loop using references to controls in userform values
    By chrisjames25 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-01-2014, 05:28 AM
  4. [SOLVED] userForm -> Frame 'top' value limited. Dynamically created controls,
    By kropeck in forum Excel Programming / VBA / Macros
    Replies: 29
    Last Post: 08-19-2013, 09:04 AM
  5. loop controls in userform except one textbox
    By gkisacik in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-28-2010, 04:30 AM
  6. Loop through controls in UserForm
    By JezLisle in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-23-2009, 05:38 AM
  7. Creating Userform Controls on Frame
    By David Myle in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2005, 11:06 AM

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