Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default String manipulation

Greetings,

I have tried to write code to do this simple string manipulation, however, I
have not been successful. I guess I am just looking at it wrong.

An example string is Baby Blue 01/02/05 . 'Baby Blue' can be various words
and also there can be more. What I need to do is strip away the date
characters so I can change them. I can handle everything except stripping
away the existing date characters. How is this programmed?


Thanks in advance for your help!!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default String manipulation

Hi Ray,

See if this makes sense...
'--------------------------------
Sub Test()
Dim strText As String
Dim strDate As String
Dim lngN As Long

strText = "Baby Blue 01/02/05"

'Find the first number
For lngN = 1 To Len(strText)
If Mid$(strText, lngN, 1) Like "#" Then
strDate = Mid$(strText, lngN, 99)
Exit For
End If
Next 'lngN

'do something to strDate if a number was found.
If Len(strDate) Then
strDate = "03/16/2005"
' Put it back together.
strText = Left$(strText, lngN - 1) & strDate
End If
MsgBox strText
End Sub
'-----------------------

Regards,
Jim Cone
San Francisco, USA


"Ray Batig" wrote in message
link.net...
Greetings,
I have tried to write code to do this simple string manipulation, however, I
have not been successful. I guess I am just looking at it wrong.
An example string is Baby Blue 01/02/05 . 'Baby Blue' can be various words
and also there can be more. What I need to do is strip away the date
characters so I can change them. I can handle everything except stripping
away the existing date characters. How is this programmed?
Thanks in advance for your help!!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default String manipulation

Function FindDate(ByVal TextIn As String) As String
Static regex As Object, matches As Object
Dim x As Integer
Dim sRet As String

If regex Is Nothing Then
Set regex = CreateObject("vbscript.regexp")
regex.Pattern = "[0-9]{1,2}/[0-9]{1,2}/[0-9]{2,4}"
regex.Global = True
regex.ignorecase = True
End If

sRet = ""
Set matches = regex.Execute(TextIn)
If matches.Count 0 Then
For x = 0 To matches.Count - 1
sRet = sRet & IIf(sRet = "", "", ",") & matches(x).Value
Next x
End If

FindDate = sRet

End Function

--
Tim Williams
Palo Alto, CA


"Ray Batig" wrote in message
link.net...
Greetings,

I have tried to write code to do this simple string manipulation, however,

I
have not been successful. I guess I am just looking at it wrong.

An example string is Baby Blue 01/02/05 . 'Baby Blue' can be various words
and also there can be more. What I need to do is strip away the date
characters so I can change them. I can handle everything except stripping
away the existing date characters. How is this programmed?


Thanks in advance for your help!!




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
String Manipulation within VBA BillCPA Excel Discussion (Misc queries) 2 December 6th 06 05:29 PM
String Manipulation String Manipulation Excel Discussion (Misc queries) 3 November 30th 05 11:51 PM
string manipulation banavas[_16_] Excel Programming 2 July 9th 04 07:55 AM
VBA String manipulation Chip Pearson Excel Programming 0 March 4th 04 11:02 PM
String Manipulation Ray Batig Excel Programming 3 December 23rd 03 12:31 AM


All times are GMT +1. The time now is 02:52 PM.

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

About Us

"It's about Microsoft Excel"