+ Reply to Thread
Results 1 to 3 of 3

Looping through label controls

  1. #1
    Forum Contributor
    Join Date
    01-21-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    106

    Looping through label controls

    Hey everyone, I have a userform in excel that's working just fine. What I would like to do is loop through cell values and then display them in a label control the same as I'm currently doing with the list and text boxes on the form. The difference is the label controls will not be used to update any values, just display them. But I'm at a loss as to how I can get this to work. Here is the code from the form that I found while searching this forum. This is a fantastic forum!

    Any help would be great!


    Private Sub UserForm_Initialize()

    Dim ctlInfo As Control
    Dim clsEvents As CControlEvents


    'A module level collection so the classes don't
    'lose scope
    Set mcControls = New Collection

    'Fill the combobox with a list of Shift time selections
    'on a separate worksheet

    Me.ShiftAssignments.List = Employees.Range("Assignments").Value
    Me.SunD.List = Employees.Range("TueShift").Value
    Me.MonD.List = Employees.Range("TueShift").Value
    Me.TueD.List = Employees.Range("TueShift").Value
    Me.WedD.List = Employees.Range("TueShift").Value
    Me.ThuD.List = Employees.Range("TueShift").Value
    Me.FriD.List = Employees.Range("TueShift").Value
    Me.SatD.List = Employees.Range("TueShift").Value

    'Loop through the controls on the form
    For Each ctlInfo In Me.Controls

    'Controls with a numeric tag are data entry controls
    'and that's what we want
    If IsNumeric(ctlInfo.Tag) Then
    'Create a new class
    Set clsEvents = New CControlEvents
    'Determine the type of control, set the public
    'withevents class variable to the control, and
    'add the class to the collection so it won't go
    'out of scope while the form is shown.
    Select Case TypeName(ctlInfo)
    Case "TextBox"
    Set clsEvents.gTextBox = ctlInfo
    mcControls.Add clsEvents, CStr(ctlInfo.Tag)

    Case "ComboBox"
    Set clsEvents.gCombo = ctlInfo
    mcControls.Add clsEvents, CStr(ctlInfo.Tag)
    End Select
    End If
    Next ctlInfo


    'Self-documenting helper sub names - you gotta love that
    DefineScroll

    'Start at the first record
    Me.scbContact.Value = Me.scbContact.Min

    End Sub

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Help! Looping through label controls the same text boxes

    That code is to create control arrays, it doesn't load controls.

    All you need is something like

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    01-21-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Help! Looping through label controls the same text boxes

    Thank you for responding. I'm still somewhat of a novice. Where would I include this line in the code above? I'd like to attach a copy of the file I'm working with but I can't seem to find where I can attach it. Can anyone help?
    Last edited by anthony1312002; 02-03-2012 at 03:28 PM.

+ 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