ComboBox List dependent on a list

ExcelRytis

New Member
Joined
Dec 22, 2017
Messages
13
Hi there,

please help me understand why my cboLnName appears empty in the userform and help me fix it? :(

Code:
Private Sub cboLnName_AfterUpdate()On Error Resume Next
Dim ws As Worksheet
Dim cPart As Range
Set ws = Worksheets("LookupData")


Me.txtAllJobs.Value = ""
Me.txtAllJobs.RowSource = ""


With ws
   .Range("CritLnName").Cells(2, 1).Value _
      = Me.cboLnName.Value
   .Columns("C:D").AdvancedFilter _
      Action:=xlFilterCopy, _
      CriteriaRange:=.Range("CritLnName"), _
      CopyToRange:=.Range("ExtJobName"), _
      Unique:=False
End With


'redefine the static named range
ThisWorkbook.Names.Add Name:="LnSelList", _
  RefersTo:="=" & ws.Name & "!" & _
  ws.Range("LnSelCatList").Address


Me.txtAllJobs.RowSource = "LnSelCatList"


End Sub


Private Sub Reset_Click()
Unload Me
performa.Show
End Sub


Private Sub submit_Click()
Dim nextrow As Range
'check for values
If Me.txtDates.Value = "" Or Me.txtOperators.Value = "" Or Me.txtAllJobs.Value = "" Or Me.txtQuantity.Value = "" Then
MsgBox "Please ensure all fields contain a value"
Exit Sub
End If
'find the next blank row
Set nextrow = Sheet4.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
'send the data to the database
With nextrow
.Value = Me.txtDates.Value
.Offset(0, 1).Value = Me.txtOperators.Value
.Offset(0, 2).Value = Me.txtAllJobs.Value
.Offset(0, 3).Value = Me.txtQuantity.Value
.Offset(0, 4).Value = Me.txtTime.Value
.Offset(0, 5).Value = Me.txtTotalTime.Value
End With
'update the worksheet
Application.ScreenUpdating = True
'clear the values
With Me
.txtAllJobs.Value = ""
.txtQuantity.Value = ""
.txtTime.Value = ""
.txtTotalTime.Value = ""
End With
'give the user the thumbs up
MsgBox "The data has been sent to the database"
End Sub


Private Sub Quit_Click()
'close the userform
Unload Me
End Sub


Private Sub txtDates_Change()
txtDates.Value = Format(txtDates.Value, "dd/mmm/yyyy")
End Sub


Private Sub txtQuantity_AfterUpdate()
'check for values and datatype
If Not IsNumeric(Me.txtQuantity.Value) Then
MsgBox "Please make sure all data is correct"
Me.txtQuantity.Value = ""
Exit Sub
End If
'send the values to the worksheet
With Sheet4
.Range("J5").Value = Me.txtDates.Value
.Range("K5").Value = Me.txtOperators.Value
.Range("L5").Value = Me.txtAllJobs.Value
.Range("M5").Value = Me.txtQuantity.Value
End With
'retrieve the results
With Me
.txtTime.Value = Sheet4.Range("N5").Value
.txtTime.Value = Format(Me.txtTime.Value, "General Number")
.txtTotalTime.Value = Sheet4.Range("O5").Value
.txtTotalTime.Value = Format(Me.txtTotalTime.Value, "General Number")
End With
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi ExcelRytis,

I'm not entirely sure why it isn't working, but you could try simply using the ComboBox.AddItem method
 
Upvote 0
Hi Danners,

would you kindly demonstrate where and how do i have to place this in my code for it to work?
 
Upvote 0
Hi ExcelRytis,

Unfortunately I can't access your link to download the document, as filesharing sites are blocked on our domain. I can download it later once I'm at home and take a closer look there. Just to check though, you've set the RowSource for the combobox?
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,206
Members
453,022
Latest member
RobertV1609

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