Want to become an expert in VBA? So this is the right place for you. This blog mainly focus on teaching how to apply Visual Basic for Microsoft Excel. So improve the functionality of your excel workbooks with the aid of this blog. Also ask any questions you have regarding MS Excel and applying VBA. We are happy to assist you.

Get a position of a character in a string

There are times we need to get the position of a certain character in a string.Below is a vba code which can be used to get a position of certain character.

Think there is a sentence or a word in a cell "C3".

So below code can be used to get the position of "@" in that sentence or word.


    Dim cellValue As String

    Dim PosOfAt As Integer

    Dim WS1 As Worksheet
    Dim Rng As Range
    Set WS1 = Worksheets("Sheet1")
    Set Rng = WS1.Range("C3")

    cellValue = Rng.Value

    PosOfAt = InStr(1, cellValue, "@", vbTextCompare)

    'Here PosOfAt equals to the position of "@"

Contact Form

Name

Email *

Message *