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