Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Challenge Parsing characters in a String

My problem is: I'm trying to parse out certain text patterns from the
first column cell to the second column cell if that cell contains those
patterns, if not nulls the cell. The text string in the first column
cell does not contain any spaces, commas, hashes or normal patterns
that you can lock onto for filtering. Tried building an Array but
having problems with the filtering. My previous attempts to do this
haven't workedand I haven't managed to find work arounds using other
functions.

The patterns I need to parse on are ## - #S, # - #S, RG###, -FO and
several others.
Example: 24-2S, 2-2S, RG142, FO
All the cells in the first column are the ones I need to look at.

Example:
Columns
--------------------------------------------------
Rows |AB2021A24-2S | |
|-------------------------|----------------------|
|AB2022A2-2S | |
|-------------------------|----------------------|
|BC2003ARG142 | |
|-------------------------|----------------------|
|IP1070A22-4S | |
|-------------------------|----------------------|

Thank You,
VectorZ

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Challenge Parsing characters in a String

Hi
What do you mean by parse? i.e We can see what you are starting with,
but what do you want to finish with??

regards
Paul

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Challenge Parsing characters in a String

Sorry I did not state that. It was late and I was tired when I posted.
What I meant was that if the cell in the first row contained that
pattern then the second column next to the first would contain only the
string it found.

Example:
Found in 1st Column Posted in 2nd Column
AB2021A24-2S 24-2S
AB2022A2-2S RG142
IP1070A22-4S 22-4S

I hope that this helps in clarifying this.

Thank you again,
VectorZ

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Challenge Parsing characters in a String

Oops. Fixed Example. Still waking up. Sorry.

Example:
Found in 1st Column Posted in 2nd Column
AB2021A24-2S 24-2S
BC2003ARG142 RG142
IP1070A22-4S 22-4S

VectorZ

  #5   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default Challenge Parsing characters in a String

Hi VectorZ,

You could try something like this. (modify to suit)

Sub ParseMyString3()
Dim s1 As String, s2 As String, s3 As String, s4 As String
Dim iPos As Integer
Dim lLastRow As Long, r As Long


s1 = "A##-#S"
s2 = "A#-#S"
s3 = "ARG###"
s4 = "FO"

With Range("A:A")
lLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
For r = 1 To lLastRow
If .Cells(r, 1) < "" Then
iPos = 0
If .Cells(r).Value Like "*" & s1 Then
.Cells(r, 2).Value = Right$(.Cells(r, 1).Value, 5)
ElseIf .Cells(r).Value Like "*" & s2 Then
.Cells(r, 2).Value = Right$(.Cells(r, 1).Value, 4)
ElseIf .Cells(r).Value Like "*" & s3 Then
.Cells(r, 2).Value = Right$(.Cells(r, 1).Value, 5)
ElseIf .Cells(r).Value Like "*" & s4 Then
.Cells(r, 2).Value = Right$(.Cells(r, 1).Value, 2)
End If
End If
Next r
End With
End Sub

HTH
Regards,
Garry


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Challenge Parsing characters in a String

GS Thank you VERY much. That did the trick. The only issue left is that
the prefix of A in the pattern can change form an A through Z in
character(see example of characters). Changed to this. One thing I'll
have to remember is when adding common patterns to add the longer ones
first to filter before going to the shorter common patterns (see
example of patterns).

Example of Characters:
AB2021A24-2S has an A24-2S but the A before the 24-2S can range from an
A to Z. The
BC2003ARG142 can be filtered off of RG and same with FO and many others

Example of Patterns:
s1 = "###-#S"
s2 = "##-#S"
s3 = "#-#S"

Changed Code and works great:

Sub ParseMyString3()
Dim s1 As String, s2 As String, s3 As String, s4 As String
Dim iPos As Integer
Dim lLastRow As Long, r As Long

s1 = "##-#S"
s2 = "#-#S"
s3 = "RG###"
s4 = "FO"

With Range("A:A")
lLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
For r = 1 To lLastRow
If .Cells(r, 1) < "" Then
iPos = 0
If .Cells(r).Value Like "*" & s1 Then
.Cells(r, 2).Value = Right$(.Cells(r, 1).Value, 5)
ElseIf .Cells(r).Value Like "*" & s2 Then
.Cells(r, 2).Value = Right$(.Cells(r, 1).Value, 4)
ElseIf .Cells(r).Value Like "*" & s3 Then
.Cells(r, 2).Value = Right$(.Cells(r, 1).Value, 5)
ElseIf .Cells(r).Value Like "*" & s4 Then
.Cells(r, 2).Value = Right$(.Cells(r, 1).Value, 2)
End If
End If
Next r
End With
End Sub

  #7   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default Challenge Parsing characters in a String

A correction is needed for s4, it should be s4 = "-FO"

Regards,
Garry



"GS" wrote:

Hi VectorZ,

You could try something like this. (modify to suit)

Sub ParseMyString3()
Dim s1 As String, s2 As String, s3 As String, s4 As String
Dim iPos As Integer
Dim lLastRow As Long, r As Long


s1 = "A##-#S"
s2 = "A#-#S"
s3 = "ARG###"
s4 = "FO"

With Range("A:A")
lLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
For r = 1 To lLastRow
If .Cells(r, 1) < "" Then
iPos = 0
If .Cells(r).Value Like "*" & s1 Then
.Cells(r, 2).Value = Right$(.Cells(r, 1).Value, 5)
ElseIf .Cells(r).Value Like "*" & s2 Then
.Cells(r, 2).Value = Right$(.Cells(r, 1).Value, 4)
ElseIf .Cells(r).Value Like "*" & s3 Then
.Cells(r, 2).Value = Right$(.Cells(r, 1).Value, 5)
ElseIf .Cells(r).Value Like "*" & s4 Then
.Cells(r, 2).Value = Right$(.Cells(r, 1).Value, 2)
End If
End If
Next r
End With
End Sub

HTH
Regards,
Garry

  #8   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default Challenge Parsing characters in a String

You're welcome!

I wasn't sure about the consistency of the "actual" pattern so I went with
what you posted to demonstrate differentiating between similar patterns. (ie.
s2 is found in s1)Your solution to modify the patterns exact and order them
as you have is a good idea.

Regards,
Garry
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
Parsing a string simonc Excel Programming 4 March 27th 06 08:04 AM
Need help parsing a string Daminc[_38_] Excel Programming 4 January 26th 06 11:53 AM
String Parsing : Best Methods : VBA vmegha Excel Programming 1 January 23rd 06 02:25 PM
parsing a string Mark[_57_] Excel Programming 4 April 28th 05 04:42 PM
Unicode string parsing? Please help! Douglas Gennetten[_2_] Excel Programming 1 January 16th 04 08:31 AM


All times are GMT +1. The time now is 10:28 AM.

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"