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

Hello, trying to figure out how to search for some text. What i Have
is some multiple text data on line a2 to a9 , what i need to do is
search each line and find the first instance of the letters BKN or OVC
then take the next three digits after that and place it into the
corresponding row B, (for ex. if a2 is bkn011 is in line a2 then b2
is 011). Then if there is no BKN or OVC i need to look for FEW or SCT
and then put the either the FEW or SCT along with the three digitsin
parenthesis. ( for ex if a2 is sct033 then be will be (sct033). Any
help would be appreciated. Thank You.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Search for certain string

Ryan,

Try the macro below.

HTH,
Bernie
MS Excel MVP

Sub Macro1()
Dim myCell As Range

Set myCell = Columns("A:A").Find(What:="BKN", _
LookAt:=xlPart)
If Not myCell Is Nothing Then
myCell(1, 2).Value = Mid(myCell.Value, _
InStr(1, myCell.Value, "BKN") + 3, 3)
Exit Sub
End If
Set myCell = Columns("A:A").Find(What:="OVC", _
LookAt:=xlPart)
If Not myCell Is Nothing Then
myCell(1, 2).Value = Mid(myCell.Value, _
InStr(1, myCell.Value, "OVC") + 3, 3)
Exit Sub
End If
Set myCell = Columns("A:A").Find(What:="FEW", _
LookAt:=xlPart)
If Not myCell Is Nothing Then
myCell(1, 2).Value = "(" & Mid(myCell.Value, _
InStr(1, myCell.Value, "FEW"), 6) & ")"
Exit Sub
End If
Set myCell = Columns("A:A").Find(What:="SCT", _
LookAt:=xlPart)
If Not myCell Is Nothing Then
myCell(1, 2).Value = "(" & Mid(myCell.Value, _
InStr(1, myCell.Value, "SCT"), 6) & ")"
Exit Sub
End If
End Sub


"Ryan" wrote in message
om...
Hello, trying to figure out how to search for some text. What i Have
is some multiple text data on line a2 to a9 , what i need to do is
search each line and find the first instance of the letters BKN or OVC
then take the next three digits after that and place it into the
corresponding row B, (for ex. if a2 is bkn011 is in line a2 then b2
is 011). Then if there is no BKN or OVC i need to look for FEW or SCT
and then put the either the FEW or SCT along with the three digitsin
parenthesis. ( for ex if a2 is sct033 then be will be (sct033). Any
help would be appreciated. Thank You.



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
search for a string santana New Users to Excel 1 April 23rd 10 03:47 AM
Search for string containing richzip Excel Discussion (Misc queries) 5 January 14th 10 09:49 PM
How to search a string from the right ? EuroMaverick Setting up and Configuration of Excel 2 March 28th 07 09:20 PM
to search for a string and affect data if it finds the string? Shwaman Excel Worksheet Functions 1 January 11th 06 12:56 AM
Q: search in string JIM.H. Excel Discussion (Misc queries) 5 January 5th 05 10:24 PM


All times are GMT +1. The time now is 09:38 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"