Av8tordude
Well-known Member
- Joined
- Oct 13, 2007
- Messages
- 1,074
- Office Version
- 2019
- Platform
- Windows
I'm trying to remove the first 3 characters from a string, but it gives me an error. I tried Mid(rCell.Value, 3) in the code, but still errors. Can some help. Thx
VBA Code:
Private Sub UpdateList()
Dim Dic As Object: Set Dic = CreateObject("Scripting.Dictionary")
Dim rCell As Range, x, y, z
x = Wks.Cells(Rows.Count, "A").End(xlUp).Row
cbName.Clear
If x > 6 Then
For Each rCell In Wks.Range("A7:A" & x)
If Not Dic.Exists(Mid(rCell.Value, 3)) Then ' <--------Here
Dic.Add rCell.Value, Nothing
End If
Next rCell
cbName.List = Dic.Keys
With cbName
For x = LBound(.List) To UBound(.List)
For y = x To UBound(.List)
If .List(y, 0) < .List(x, 0) Then
z = .List(y, 0)
.List(y, 0) = .List(x, 0)
.List(x, 0) = z
End If
Next y
Next x
End With
End If
End Sub