Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Possible? find string and put in next cell...

Good morning!

Is this possible?
I have the following list:

LastName FirstName
Stevans variant Stevens Marilyn
Rogers Brendon variant Brendan

I would like to find the string "variant" and take what ever is after
it and put it in the cell under it along with the first or last name
that goes with it. ex:

LastName FirstName
Stevans Marilyn
Stevens Marilyn
Rogers Brendon
Rogers Brendan

I am thinking that I have to use something like:
If CellContainsText("variant") Then

cut what ever is after it and paste it in next cell with first or last
name then clean it??

ThisWorkbook.worksheets("Sheet1").Columns("A:B").c ells.Replace _
What:="variant", Replacement:="", _
SearchOrder:=xlByColumns, MatchCase:=True

?? any suggestions would be appreciated!

Thanks,
MC





------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Possible? find string and put in next cell...

Try this. It assumes the data is in columns A & B.

Sub Macro1()
Dim c As Range
Dim str1 As String
Dim iPos As Integer
For Each c In Range("A:B")
iPos = InStr(c, "variant")
If iPos 0 Then
str1 = c
Rows(c.Row).Insert Shift:=xlDown
If c.Column = 1 Then
Cells(c.Row, 1) = Left(str1, iPos - 1)
Cells(c.Row - 1, 1) = Right(str1, Len(str1) - iPos - 7)
Cells(c.Row, 2) = c.Offset(0, 1)
Cells(c.Row - 1, 2) = c.Offset(0, 1)
Else ' c.Column = 2
Cells(c.Row, 2) = Left(str1, iPos - 1)
Cells(c.Row - 1, 2) = Right(str1, Len(str1) - iPos - 7)
Cells(c.Row, 1) = c.Offset(0, -1)
Cells(c.Row - 1, 1) = c.Offset(0, -1)
End If
End If
Next c
End Sub

HTH,
Merjet


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Possible? find string and put in next cell...

the whole thing is that I am comparing a sheet to that sheet looking
form matches.....thnks to Tom Ogilvy!

Set CompareRange = ThisWorkbook. _
worksheets("Sheet1").Range("A4:A80")
For Each x In Selection.Columns(1).cells
For Each y In CompareRange
If UCase(x) = UCase(y) And UCase(x.Offset(0, 1)) = UCase(y.Offset(0,
1)) Then
x.Offset(0, 2) = x & ", " & x.Offset(0, 1)
If x = 0 Then
x.Offset(0, 2) = ""
End If
End If
Next y
Next x

But now the list I am trying to match against contains "variants" as
mentioned above...so I was thinking that was the quickest solution or
can I use something like:

ElseIf UCase(x) = UCase(y) And CellContainsText(y.Offset(0, 1),
"variant") Then

which works fine since I am comparing last names first, but if the
lastname contains "variant" it won't match, this will flag if it
matches the lastname and the first name contains the string
"variant".... I was looking at using "like" but I couldn't get that to
work.

????



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Possible? find string and put in next cell...

Which range would contain the entries which have variant, the x range
(Selection.Columns(1).cells) or the Y range
(Worksheets("Sheet1").Range("A4:A80")/CompareRange)?

--
Regards,
Tom Ogilvy

"excelnewbie" wrote in message
...
the whole thing is that I am comparing a sheet to that sheet looking
form matches.....thnks to Tom Ogilvy!

Set CompareRange = ThisWorkbook. _
worksheets("Sheet1").Range("A4:A80")
For Each x In Selection.Columns(1).cells
For Each y In CompareRange
If UCase(x) = UCase(y) And UCase(x.Offset(0, 1)) = UCase(y.Offset(0,
1)) Then
x.Offset(0, 2) = x & ", " & x.Offset(0, 1)
If x = 0 Then
x.Offset(0, 2) = ""
End If
End If
Next y
Next x

But now the list I am trying to match against contains "variants" as
mentioned above...so I was thinking that was the quickest solution or
can I use something like:

ElseIf UCase(x) = UCase(y) And CellContainsText(y.Offset(0, 1),
"variant") Then

which works fine since I am comparing last names first, but if the
lastname contains "variant" it won't match, this will flag if it
matches the lastname and the first name contains the string
"variant".... I was looking at using "like" but I couldn't get that to
work.

????



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Possible? find string and put in next cell...

Hi Tom! Hope everything is well.

The variant is in the Y/Compare Range.

Thanks,

MC:)



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Possible? find string and put in next cell...

This should do what you want

Sub Tester1()
Dim x As Range, y As Range
Dim y1 As Range, x1 As Range
Dim ya As String, yb As String
Dim CompareRange As Range
Dim sStr As String
Set CompareRange = ThisWorkbook. _
Worksheets("Sheet1").Range("A4:A80")
For Each x In Selection.Columns(1).Cells
For Each y In CompareRange
If UCase(x) = UCase(y) Or _
UCase(x.Offset(0, 1)) = UCase(y.Offset(0, 1)) Then
Set x1 = x.Offset(0, 1)
Set y1 = y.Offset(0, 1)
Select Case True
Case InStr(1, y, _
"variant", vbTextCompare) = 0 _
And InStr(1, y.Offset(0, 1), _
"variant", vbTextCompare) = 0
If UCase(x) = UCase(y) And _
UCase(x1) = UCase(y1) Then
x.Offset(0, 2) = x & ", " & x1
If IsNumeric(x) Then
If x = 0 Then
x.Offset(0, 2) = ""
End If
End If
End If
Case InStr(1, y, _
"variant", vbTextCompare) 0 _
And InStr(1, y1, _
"variant", vbTextCompare) = 0
sStr = y.Value
sStr = Application.Trim( _
Application.Substitute(sStr, "variant", ""))
ya = Left(sStr, InStr(sStr, " ") - 1)
yb = Right(sStr, Len(sStr) - (Len(ya) + 1))
If UCase(x) = UCase(ya) Or UCase(x) = UCase(yb) And _
UCase(x1) = UCase(y1) Then
x.Offset(0, 2) = x & ", " & x1
End If
Case InStr(1, y, _
"variant", vbTextCompare) = 0 _
And InStr(1, y1, _
"variant", vbTextCompare) 0

sStr = y1.Value
sStr = Application.Trim( _
Application.Substitute(sStr, "variant", ""))
ya = Left(sStr, InStr(sStr, " ") - 1)
yb = Right(sStr, Len(sStr) - (Len(ya) + 1))
If UCase(x1) = UCase(ya) Or UCase(x1) = UCase(yb) And _
UCase(x) = UCase(y) Then
x.Offset(0, 2) = x & ", " & x1
End If
End Select
End If
If IsNumeric(x) Then
If x = 0 Then
x.Offset(0, 2) = ""
End If
End If

Next y
Next x
End Sub


--
Regards,
Tom Ogilvy


excelnewbie wrote in message
...
Hi Tom! Hope everything is well.

The variant is in the Y/Compare Range.

Thanks,

MC:)



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Possible? find string and put in next cell...

Hi Tom,

It is amazing how you come up with this so quickly!

I tested the code, but it isn't working :( I am going to try to get
it to work.

Thanks soo much!,

MC



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Possible? find string and put in next cell...

Hey Tom


I got it! Just had to replace "variant" with " " instead of
""/nothing...

Thanks again!

MC


Merjet thank you too for your input!!! :)



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Possible? find string and put in next cell...

I would have to be a mind reader to know about that <g

--
Regards,
Tom Ogilvy

"excelnewbie" wrote in message
...
Hey Tom


I got it! Just had to replace "variant" with " " instead of
""/nothing...

Thanks again!

MC


Merjet thank you too for your input!!! :)



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



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
Find cell entry contained anywhere within a text string VickiMc Excel Worksheet Functions 2 February 12th 09 03:07 AM
How can I find a value from one cell in a char string in another? tiredazdaddy Excel Worksheet Functions 2 November 20th 08 05:40 PM
Find a specific formatted string in a cell KCK Excel Worksheet Functions 1 April 16th 08 09:16 PM
FIND / SEARCH text compare cell to string in 3rd cell nastech Excel Discussion (Misc queries) 0 October 29th 07 02:51 AM
Need to find the right-most cell value in a string of cells -dc- Excel Worksheet Functions 2 March 8th 05 07:28 PM


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