Thank you all for your help.
Text to columns won't help with this issue because I don't want to separate
the cell from all of its spaces, I want to be able to select from the cell
( and other cells in the same column ) a specific number of spaces.
For example, (which I realize could have helped earlier)
I have the following in cell A2 .... Product Code followed by the Product
Name and Description, then another Product Part Code and the Cost.
All of this appears in one cell when I'm pasting it from Adobe Reader to
Excel. There are only spaces separating them. I don't want the description
broken up from everything else.
I want to tell the cells adjacent to A2 to separate it at the space after
the product code(space 1) then again in between the name and description
(space 7 or 8 or 9. Its never the same) then again at the product part code
(space 2 from the right) and the cost (space 1 from the right)
Here is a UDF that I think will do what you describe. However, if your
different sections have unique ways of being identified, other than their
location as determined by <space>s, there might be another way to do this.
In any event, the function that you enter is:
=SepAtSpace(cell_ref,SP1,SP2)
SP1 is the first space where you want to start the extraction, and should be
entered as 0 (zero) if you want to start at the beginning of the string.
SP2 is the last space you wish to extract, or the number of spaces + 1 if you
want to extract to the end of the string.
The function counts multiple spaces between words as a single space.
The function will return a blank if
SP1 >= SP2
SP1 or SP2 are not in the range 0 to number of spaces + 1
To enter the UDF, <alt-F11> opens the VB Editor. Ensure your project is
highlighted in the Project Explorer window, then Insert/Module and paste the
code below into the window that opens.
=====================================
Option Explicit
Function SepAtSpace(str As String, SP1 As Long, SP2 As Long) As String
Dim re As Object
Dim mc As Object
Dim sPat As String
Dim i As Long
Set re = CreateObject("vbscript.regexp")
'create sPat
sPat = "^"
sPat = sPat & "(\S+\s+){" & SP1 & "}"
sPat = sPat & "((\S+\s+){" & SP2 - SP1 - 1 & "}\S+(\s|$))"
re.Pattern = sPat
If re.test(str) = True Then
Set mc = re.Execute(str)
SepAtSpace = mc(0).submatches(1)
End If
End Function
=================================
--ron