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
 
Okay so now I used the LnList name as the rowsource and changed it to column G, however now it doesn't automatically find all the jobs for that. What am I missing now?
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You can either use the "RowSource" in column "G".

NB:- Right Click sheet Tab , select "View Code" , click "Ctrl + R" to see the Properties window in code module.
In properties window , Double click "performas" to see Userform Layout.
Right click 3rd Combobox, Select "Properties" to see its Properties Window.
Scroll down to "RowSource" and enter :- G2:G8
The "RowSource" should now be set for "cboLnName"



Or Place this code in the Userform "Performas" code module.
The data will load when the Userform is opened.

Code:
Private Sub UserForm_Initialize()
Dim Rng As Range, Dn As Range, n As Long
Set Rng = Range("C2", Range("C" & Rows.Count).End(xlUp))
With CreateObject("scripting.dictionary")
    .CompareMode = vbTextCompare
    For Each Dn In Rng
        .Item(Dn.Value) = Empty
    Next
cboLnName.List = Application.Transpose(.Keys)
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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