+ Reply to Thread
Results 1 to 7 of 7

find the position of an underline word in string.

Hybrid View

mouaffaq find the position of an... 11-22-2016, 06:10 PM
Subverter Re: find the position of an... 11-23-2016, 05:35 AM
mouaffaq Re: find the position of an... 11-23-2016, 05:52 AM
mouaffaq Re: find the position of an... 11-23-2016, 05:57 AM
Subverter Re: find the position of an... 11-23-2016, 06:14 AM
mouaffaq Re: find the position of an... 11-25-2016, 10:05 AM
mouaffaq Re: find the position of an... 11-27-2016, 05:59 AM
  1. #1
    Registered User
    Join Date
    06-08-2016
    Location
    jordan
    MS-Off Ver
    2010
    Posts
    33

    find the position of an underline word in string.

    Hi guys;

    Please help in this>

    I have column A have data with 1 or more underlined word, i need to find the position of each underlined word in each string in cells;

    i.e.

    Hi How are you guys.

    Result is 2,5. in cell B.

    Could be one word or more.

    Thanks A Lot.
    Last edited by mouaffaq; 11-23-2016 at 04:23 AM.

  2. #2
    Registered User
    Join Date
    11-01-2012
    Location
    Cairo, Egypt
    MS-Off Ver
    MS Office 2013
    Posts
    76

    Re: find the position of an underline word in string.

    Assuming you have the data in Column "A" .. Try the following code:

    Private Sub CommandButton1_Click()
    Dim oCell As Range
    Dim strTest As String
    Dim strArray() As String
    Dim X As Integer
    Dim Y As Integer
    Dim intLenStr() As Integer
    Dim intStrIndex As String
    Dim intStart As Integer
    Dim strPos As String
    Dim intCount As Integer
    Dim i As Integer
    
    Application.ScreenUpdating = False
    
    On Error GoTo errHandle
    For Each oCell In Range("A:A")
    oCell.Offset(0, 1).ClearContents
    intCount = intCount + 1
    strTest = oCell.Value
    strArray = Split(strTest, " ")
    X = LBound(strArray)
    Y = UBound(strArray)
    
    ReDim intLenStr(X To Y)
    
    intStart = 1
        For i = X To Y
            intStrIndex = i + 1 'Index the current string.
            intLenStr(i) = Len(strArray(i))
            With oCell.Characters(Start:=intStart, Length:=intLenStr(i)).Font
            If .Underline = xlUnderlineStyleSingle Then
                oCell.Offset(0, 1) = oCell.Offset(0, 1) & intStrIndex & ".."
            End If
            End With
            intStart = intStart + intLenStr(i) + 1
        Next i
    Next oCell
    
    Application.ScreenUpdating = True
    
    errHandle:
    Application.ScreenUpdating = True
    MsgBox (intCount - 1) & " Rows checked", vbInformation
    End Sub
    Last edited by Subverter; 11-24-2016 at 04:07 AM.

  3. #3
    Registered User
    Join Date
    06-08-2016
    Location
    jordan
    MS-Off Ver
    2010
    Posts
    33

    Re: find the position of an underline word in string.

    Thank you very much man
    but i noticed that it only find the position of the first occurrence of the underline word
    that means if a string have more than one underline word it should specify the position of all occurences positions separated by comma in B

  4. #4
    Registered User
    Join Date
    06-08-2016
    Location
    jordan
    MS-Off Ver
    2010
    Posts
    33

    Re: find the position of an underline word in string.

    no its perfect
    forget the last reply
    there was some errors in my data
    thanks man

  5. #5
    Registered User
    Join Date
    11-01-2012
    Location
    Cairo, Egypt
    MS-Off Ver
    MS Office 2013
    Posts
    76

    Re: find the position of an underline word in string.

    You welcome, ya m3allem 😁😁

  6. #6
    Registered User
    Join Date
    06-08-2016
    Location
    jordan
    MS-Off Ver
    2010
    Posts
    33

    Re: find the position of an underline word in string.

    انته المعلم
    ومنك نتعلم

  7. #7
    Registered User
    Join Date
    06-08-2016
    Location
    jordan
    MS-Off Ver
    2010
    Posts
    33

    Re: find the position of an underline word in string.

    salam Bro
    when applying the code to the whole data there were some cells without data in, and some with errors in calculating info for wordID,
    you can find data in http://www.Almutadaber.com/excel.xlsx
    there are 4 sheets.
    kindly note that data to be calculated is in column B and your procedure should fill data in column D
    also kindly note that this is a Quran project so data should be 100% accurate.
    I appreciate if you can help me in this.

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Find the position of the first nr in a string
    By Jacob2010 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-08-2014, 01:52 PM
  2. [SOLVED] Find the position of a substring in a string
    By nemo66ro in forum Excel General
    Replies: 6
    Last Post: 10-22-2012, 01:21 AM
  3. Add the word ERROR in the 133rd position after a string of characters in a cell
    By viantahu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-24-2012, 04:32 PM
  4. getting position of a word in a string
    By vkkishore_s in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-20-2007, 10:33 AM
  5. [SOLVED] find nth position of a string
    By TUNGANA KURMA RAJU in forum Excel General
    Replies: 6
    Last Post: 10-18-2005, 09:05 AM
  6. find position of a number in a string
    By Dave Peterson in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-06-2005, 11:05 PM
  7. [SOLVED] find position of a number in a string
    By fullers80 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-06-2005, 01:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1