remove first 3 characters from string

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. 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

1594739628692.png
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I suspect the error comes on the next line.
You are adding the full cell cell value to the dictionary, not the 4th character onwards.
 
Upvote 0
I'm guessing you mean this?


VBA Code:
        If Not Dic.Exists(Mid(rCell.Value, 5)) Then
            Dic.Add Mid(rCell.Value, 5), Nothing
        End If
 
Upvote 0
Ok...It works. Thank you for your help and leading in the right direction.
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,237
Messages
6,123,811
Members
449,127
Latest member
Cyko

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