Dear Forum experts,
Kindly guide me for the following error:
I have developed a user form for data entry purpose. i have tried for two things.
1. In the combo box (cbsitename), i have done a filter with text option. like , if i type "S" the name start with "S" will come automatically.
2. In the combo box (cbsitename), if i select any value, automatically, dependent values will appear for the next text box.
Errors:
1. As per the given code - Compile error: "Duplicate Declaration in the current scope" is coming
2. If i remove the underlined code : Dim ws As Worksheet" Runtime Error 9: Subscript out of range is coming.
Kindly guide me, how to fix the issue.
Regards
Private Sub UserForm_Initialize()
Dim i As Long, LastRow As Long, ws As Worksheet
Set ws = Sheets(“Sitedetails”)
LastRow = ws.Range(“A” & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
Me.cbsitename.AddItem ws.Cells(i, “A”).Value
Next i
For i = 2 To LastRow
If Val(Me.cbsitename.Value) = ws.Cells(i, “A”) Then
MsgBox Me.cbsitename.Value
Me.txtsitecode = ws.Cells(i, “B”).Value
Me.txttown = ws.Cells(i, “C”).Value
End If
Next i
Dim clblsitename As Range
Dim ws As Worksheet
Set ws = Worksheets("Sitedetails")
For Each clblsitename In ws.Range("sitename")
With Me.cbsitename
.AddItem clblsitename.Value
.List(.ListCount - 1, 1) = clblsitename.Offset(0, 1).Value
End With
Next clblsitename
Dim clbldistrict As Range
Dim clblsvby As Range
Set ws = Worksheets("ListReference")
For Each clbldistrict In ws.Range("districtslist")
With Me.cbdistricts
.AddItem clbldistrict.Value
.List(.ListCount - 1, 1) = clbldistrict.Offset(0, 1).Value
End With
Next clbldistrict
For Each clblsvby In ws.Range("staffslist")
With Me.cbsvdoneby
.AddItem clblsvby.Value
End With
Next clblsvby
For Each clblsvaccompany1 In ws.Range("staffslist")
With Me.cbsvacc1
.AddItem clblsvaccompany1.Value
End With
Next clblsvaccompany1
For Each clblsvaccompany2 In ws.Range("staffslist")
With Me.cbsvacc2
.AddItem clblsvaccompany2.Value
End With
Next clblsvaccompany2
End Sub
Bookmarks