Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Need to edit string in cell

I am learning some vba and am trying to delete some useless info both before
and after my needed info (job #)

ex. "hello:07-021 goodbye"

I need to have the "hello:" and " goodbye" leaving only the job number.
Note: all the job numbers start with two digits, have a hyphen, and end with
three digits such as "00-000"

Any help would be great . . . thank you
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,934
Default Need to edit string in cell

If your text can **never** have a hyphen in **front** of the job number,
then you can do this..

Text = "hello:07-021 goodbye"
JobNum = Mid(Text, InStr(Text, "-") - 2, 6)

--
Rick (MVP - Excel)


"jorlypong" wrote in message
...
I am learning some vba and am trying to delete some useless info both
before
and after my needed info (job #)

ex. "hello:07-021 goodbye"

I need to have the "hello:" and " goodbye" leaving only the job number.
Note: all the job numbers start with two digits, have a hyphen, and end
with
three digits such as "00-000"

Any help would be great . . . thank you


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Need to edit string in cell

You could set up the following user defined function using VBA and then
within your workbook the function could be used much like a built in
Worksheet function.

'--------------------------------------------

Function GetJobNum(myRange As Range) As String

Dim strResult As String
strResult = ""

Set objRegEx = CreateObject("VBScript.RegExp")

objRegEx.Global = True
objRegEx.Pattern = "\d{2}-\d{3}"

Set colMatches = objRegEx.Execute(myRange.Value)

If colMatches.Count 0 Then
For Each objMatch In colMatches
strResult = strResult & " " & objMatch.Value
Next objMatch
End If

GetJobNum = LTrim(strResult)

Set objRegEx = Nothing

End Function

'---------------------------------------------

If you string was in cell a1, then
=GetJobNum(a1)
would return
07-021

Steve Yandl



"jorlypong" wrote in message
...
I am learning some vba and am trying to delete some useless info both
before
and after my needed info (job #)

ex. "hello:07-021 goodbye"

I need to have the "hello:" and " goodbye" leaving only the job number.
Note: all the job numbers start with two digits, have a hyphen, and end
with
three digits such as "00-000"

Any help would be great . . . thank you



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default Thank You

Just what the doctor ordered. Thanks for looking and helping
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reset row hight after string of text edit on a cell Tony Excel Discussion (Misc queries) 0 February 3rd 09 03:21 AM
Disable cell reference insertion with PageUp in cell edit mode. Greta Excel Discussion (Misc queries) 0 May 21st 08 03:54 PM
edit text string in column B useR Excel Discussion (Misc queries) 7 April 7th 06 10:10 PM
Why can't I edit my excel document? Edit buttons shaded. Arl @ CBC New Users to Excel 3 September 7th 05 01:18 AM
Can you make a cell with a diagonal, so that you can edit the upper and lower part of the cell? g wills New Users to Excel 3 February 17th 05 10:23 PM


All times are GMT +1. The time now is 09:46 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"