• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

If Exists, Find Replace 2nd Character From Start Of String

My aim for this is to find the second character from the left (which is a "{") and replace it with nothing. For one reason or another I'm having trouble?


Sub Find_Character_Second_From_Left_At_Start_Of_String()


Dim Cell As Range

Dim MyString As String

Dim MyRange As Range


Set MyRange = Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)


For Each Cell In MyRange


If WorksheetFunction.Mid(MyString, 2, 1) = "{" Then

MyString = WorksheetFunction.Substitute(MyString, "{", "")

End If


Next Cell

End Sub
 
MyString is the whole range, you should be doing the operations on Cell (personally, i just use "c" so I don't get mixed up with the method "Cells"). Also, Mid is not a WorksheetFunction.

Re-written for clarity:

Code:
For Each c In MyRange


If Mid(c, 2, 1) = "{" Then

c.Value = WorksheetFunction.Substitute(c, "{", "")

End If


Next c
 
Back
Top