Results 1 to 18 of 18

Pulling cell values into text boxes in a userform upon selecting a certain combobox value

Threaded View

  1. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Pulling cell values into text boxes in a userform upon selecting a certain combobox va

    Hi, nashle6,

    if you start working with VBA please take your time and have Google search for the Reddick Naming Conventions - IŽd never name a Textbox Frame, really never.

    And I would take into consideration that any item should only appear once in a ComboBox. Last thing: I wouldnŽt place 2 Sets of Textboxes which are to be populated on the change of one ComboBox but to be altered on the change of a second - I would just use one set and fill that only after the name of a person has been selected and leave them empty otherwise.

    HereŽs the code:
    Private Sub ColourDrop_Change()
    Dim lngCounter As Long
    Dim lngCol As Long
    Dim lngTB As Long
    EntrantCB.Clear
    For lngCounter = 1 To 2
      For lngCol = 1 To 3
        Controls("txtBox" & lngCounter & "_" & lngCol).Value = vbNullString
      Next lngCol
    Next lngCounter
    With Sheets("Scores")
      For lngCounter = 2 To .Cells(Rows.Count, "B").End(xlUp).Row
        If UCase(.Cells(lngCounter, "B").Value) = UCase(ColourDrop.Value) Then
          lngTB = lngTB + 1
          EntrantCB.AddItem .Cells(lngCounter, "A").Value
          For lngCol = 1 To 3
            Controls("txtBox" & lngTB & "_" & lngCol).Value = .Cells(lngCounter, 2 + lngCol).Value
          Next lngCol
        End If
      Next lngCounter
    End With
    End Sub
    
    
    Private Sub UserForm_Initialize()
    Dim wbBook As Workbook
    Dim wsSheet As Worksheet
    Dim rnData As Range
    Dim rngCell As Range
    
    Set wbBook = ThisWorkbook
    Set wsSheet = wbBook.Worksheets("Scores")
    
    With wsSheet
      Set rnData = .Range(.Range("B2"), .Range("B" & Rows.Count).End(xlUp))
    End With
    
    With Me.ColourDrop
      .Clear
      For Each rngCell In rnData
        If WorksheetFunction.CountIf(wsSheet.Range("B2:B" & rngCell.Row), rngCell) = 1 Then
          .AddItem rngCell
        End If
      Next rngCell
      .ListIndex = -1
    End With
    End Sub
    Ciao,
    Holger
    Attached Files Attached Files

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