Need combobox change to update text in textboxes

creng

New Member
Joined
Jul 22, 2015
Messages
1
I have a combobox that is filled with dates listed from Worksheet("D") of range A5:A56. I have values of textboxes that are filled in with the values of the lastrow of row 3. the combobox1.value is cells(i,1) for i = 5 to i=56. i also have currentRow = activecell.row + 1 used in column 3/C. I'd like to be able to change the value of the textboxes of oTxtBox2 after combobox1 value is changed. this is the following code:

Code:
Dim i As Integer, count As Integer   
 Dim oTxtBox As Control
    Dim ws As Worksheet
    Dim oTxtBox2 As Control
    Dim currentRow As Integer
    Dim crnRow As Integer
    
    
Private Sub ComboBox1_Change()

'update oTxtBox2 with values from cells(currentRow,3) once combobox value is changed. 
'combobox consists of dates from rows 5-56.  
        
    
End Sub


Private Sub UserForm_Initialize()


    'Find first empty cell in C column after C5
    Range("C5").Select
    ActiveCell.End(xlDown).Select
    lastRow = ActiveCell.Row + 1
    For i = 5 To 56
    ComboBox1.AddItem Worksheets("DMB").Cells(i, 1).Value
    Next i
    ComboBox1.ListIndex = lastRow - 5
    
    lastUsedCell = Sheets("Sheet1").UsedRange.Rows.count
    
    For i = 1 To lastUsedCell
        Set oTxtBox = Me.Controls.Add("Forms.TextBox.1")
        'name of each person on active roster
        oTxtBox.Text = Sheets("Sheet1").Cells(i, 1).Value


        With oTxtBox
            .Left = 5
            .Top = (.Height * (i + 1)) + (5 * i)
            .Text = oTxtBox
        End With
    
        Set oTxtBox2 = Me.Controls.Add("Forms.TextBox.1")
        
        
            With oTxtBox2
                .Left = 300
                .Top = (.Height * (i + 1)) + (5 * i)
                .Text = returnTextForBlank(oTxtBox.Text)


            End With
    
    Next i


    Set oTxtBox = Nothing
    


    With Me
        'This will create a vertical scrollbar
        .ScrollBars = fmScrollBarsVertical
        
        'Change the values of 2 as Per your requirements
        .ScrollHeight = .InsideHeight * lastUsedCell / 11
        .ScrollWidth = .InsideWidth * 9
    End With


End Sub


Function returnTextForBlank(rosterName As String) As String
   
    For Each ws In Sheets
        If ws.Name <> "Sheet1" Then
        If ws.Name <> "Spreads" Then
        If ws.Name <> "Commissions" Then
        If ws.Name <> "Remittances" Then
    Range("C5").Select
    ActiveCell.End(xlDown).Select
    currentRow = ActiveCell.Row + 1
    crntRow = currentRow
    
    
            If ws.Range("A1").Value = rosterName Then
                returnTextForBlank = ws.Cells(crntRow, 3).Value
                Exit Function
            End If
            
        End If
        End If
        End If
        End If
    Next ws
    returnTextForBlank = ""
End Function

 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top