I am creating a dependent list combo box in userform. I have 10,000 rows of data. While using the following code i am having error at red color line. "Runtime Error 13; Type Mismatch". How to resolve this? Or is there more efficient way?
Code:
Private Sub cmbDistrict_Change()
Dim i As Integer
cmbDistrict.Clear
With Sheets("Data")
LastRow = .Range("C" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If .Cells(i, "C") = cbmBankName Then
cmbDistrict.AddItem .Cells(i, "E")
End If
Next
End With
End Sub
Private Sub UserForm_Activate()
Dim LastRow As Long
Dim LastVal, NextVal
Dim i As Integer
Application.ScreenUpdating = False
With Sheets("Data")
LastRow = .Range("C" & Rows.Count).End(xlUp).Row
.Range("A1:Z" & LastRow).Sort Key1:=.Range("C2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
For i = 2 To LastRow
NextVal = .Cells(i, "C")
If Not NextVal = LastVal Then
[B][COLOR=Red]cmbBankName.AddItem NextVal[/COLOR][/B]
End If
LastVal = NextVal
Next
End With
Me.cmbBankName.SetFocus
Application.ScreenUpdating = True
End Sub