insanalyst

New Member
Joined
Dec 2, 2011
Messages
4
I have a WB where column A contains stocks and stock symbols. The stock symbols represent the last 1-4 letters in each cell. Because each stock name (and symbol) is of different length and may or may not have multiple spaces, the traditional means of "reverse contatenation" aren't helping (e.g. text to columns, =RIGHT(text,FIND(" ",text)), etc.) any ideas? WB is several thousand rows long so a clean solution is preferred. perhaps a way to make the FIND function return the last space in the text?
 

Trouttrap2

Well-known Member
Joined
May 11, 2010
Messages
608
Are you trying to extract the last 4 characters, but not include the spaces?
Could you provide an example of your data and the expected outcome.
 

insanalyst

New Member
Joined
Dec 2, 2011
Messages
4
I am trying to extract the stock symbol. It could be anywhere from 1-4 letters long depending on the symbol. I can trim spaces if necessary. here is an example:
<TABLE style="WIDTH: 213pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=284><COLGROUP><COL style="WIDTH: 213pt; mso-width-source: userset; mso-width-alt: 10386" width=284><TBODY><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; WIDTH: 213pt; HEIGHT: 15pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" id=td_post_251209 height=20 width=284><TABLE style="WIDTH: 213pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=284><COLGROUP><COL style="WIDTH: 213pt; mso-width-source: userset; mso-width-alt: 10386" width=284><TBODY><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; WIDTH: 213pt; HEIGHT: 15pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" id=td_post_251209 height=20 width=284>AGILENT TECHNOLOGIES IN A</TD></TR></TBODY></TABLE>
ALLSCRIPTS HEALTHCARE MDRX
</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 15pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" height=20>ALPHA NATURAL RESOURCES ANR</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 15pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" height=20>ALTERA CORP ALTR</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 15pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" height=20>ALTRIA GROUP INC MO</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: #ece9d8; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: transparent; HEIGHT: 15pt; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8" height=20>AMAZON COM INC AMZN</TD></TR></TBODY></TABLE>

In all cases the characters after the last space represent the stock symbol
 

chirp

Active Member
Joined
Nov 17, 2011
Messages
338
you can use this formula:

=RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1," ","*",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))))

or this function:

Code:
Public Function getLastWord(ByVal str As String, _
                            Optional tst As Boolean) As String

Dim funcTst As Boolean, lenStr As Long, ndx As Long
tst = False
On Error GoTo exitFunc

str = RTrim$(str)
lenStr = Len(str)
ndx = InStrRev(str, Chr(32))

getLastWord = Mid$(str, ndx + 1, lenStr - ndx)
tst = True
exitFunc:
End Function
 

insanalyst

New Member
Joined
Dec 2, 2011
Messages
4
Chirp, this worked like a charm, thankyou. Just familiarizing myself with LEN. This worked so smoothly
 

c_m_s_jr

Well-known Member
Joined
Mar 23, 2009
Messages
1,561
Another alternative:

=TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",100)),4))
 

Forum statistics

Threads
1,082,126
Messages
5,363,315
Members
400,725
Latest member
excelingtolearn

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top