I am trying to write a Do Loop that enters into a long string and returns the place of the space before an email address and the place of the space after. Using InStr() I have been able to locate the end of the email address. Now I need to locate the beginning to then use Mid() to pull the address out. I see that InStrRev() should start at the end of a string and then search, but looking at actual manuals it appears it just gives the second instance of a character. For example:
My string is:
please shoot me an email. My E-Mail: [email protected] If you cannot make it call me.
What I have done so far is returned the place of the @ , which in this case if 42. Then I used InStr() to return the place of the first " " after the @. Which in this case is, 52. I wish to return the place of the first " " BEFORE the @. In this case it should be 37. My plan then is to use Mid(37, 15). Fifteen being the difference of 52 & 37. I have tried using InStrRev() to return 37 but cannot get it to work. Any suggestions? below is my code.
x = 2
Do
Cells(x, 11).Select
Cells(x, 11).Value = (InStrRev(Cells(x, 9), Cells(x, 2), " "))
x = x + 1
On Error Resume Next
Loop Until Cells(x, 2).Value = ""
Where (x,9) is the place of the @ and (x, 2) is the string.
How about: