Copy only a certain section of a cell

J

James Heathershaw

Hello

Is there a way to copy all of the data in a cell up to a certain character? I have the following data contained in a cell, and want to copy everything up to the first -v and paste it into another cell. The trouble I am having is that the data to copy will be of a varying length, so I can not use anything involving a count function. I would prefer to do this eiter by macro or VBA:

/data/projects/scripts/RunDataStageJob.sh -p OPER_BGP -j SeqBGP05TEST -r -v 'pDB_RPD_DSN=CUSTDBO' -v 'pDB_RPD_SCHEMA=USR' -v 'pDB_RPD_USER=user' -v 'pDB_RPD_PWD=******' -v 'pDB_STAGING_DSN=DATA' -v 'pDB_STAGING_SCHEMA=OPER_WORKING' -v 'pDB_STAGING_USER=dtaix' -v 'pDB_STAGING_PWD=******' ?v 'pWORKING_DIR=/data/projects/OPER/working' ?v 'pHASH_DIR=/data/projects/OPER/hash' -v 'pMAPPING_DIR=/data/projects/OPER/mapping'

Thank you


Submitted via EggHeadCafe - Software Developer Portal of Choice
Silverlight Google Search API Source Code Sample
http://www.eggheadcafe.com/tutorial...f-1fa1c7a76205/silverlight-google-search.aspx
 
D

Dave Peterson

I'd do it manually.

If I had to use another cell (column of cells????), I'd just copy the original
range to that column.

Then Edit|Replace
What: -v*
with: (leave blank)
replace all

You could use a formula if you wanted:
=search("-v",a1)
will give the position for the first -v.

So
=left(a1,search("-v",a1)-1)
or
=trim(left(a1,search("-v",a1)-1))
should work ok.
 
R

Rick Rothstein

Since you wanted a coded solution, give this macro a try...

Sub ParseFirstMinusV()
Dim Cell As Range
For Each Cell In Selection
Cell.Value = Split(Cell.Value & "-v", "-v", , vbTextCompare)(0)
Next
End Sub

It will process all cells with the current selection.

--
Rick (MVP - Excel)


in message
news:[email protected]...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top