This seems to do it
Sub iffound()
For Each cel In Range("h1:h5")
With Columns("i")
Set c = .Find(cel, lookat:=xlPart)
If Not c Is Nothing Then
firstAddress = c.Address
Do
mc = Cells(c.Row, cel.Column).End(xlToRight).Column + 1
Cells(c.Row, mc) = cel.Row
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
Next cel
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
[email protected]
Don Guillett wrote:
Either of these will do. Just change the references to suit.
Sub ifinstr()
For Each x In Range("h1:h5")
For Each c In Range("i1:i5")
If InStr(1, c, x) > 0 Then c.Offset(, 1) = x.Row
Next c
Next x
End Sub
Sub iffound()
For Each cel In Range("h1:h5")
With Columns("i")
Set c = .Find(cel, lookat:=xlPart)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Offset(, 1) = cel.Row
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
Next cel
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
[email protected]
Don Guillett wrote:
Give some detailed examples of what you would put in col C and
what
you
expect in col D
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
[email protected]
Don Guillett wrote:
Have a look in the vba help index for FINDNEXT
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
[email protected]
I have sheet with 2 columns and 1200 rows.
Column A is numbers 1 to 1200
Column B is varying length text strings.
I wish to paste different longer text strings into column C
and
then
find if any of the strings in column B occur within the
strings
in
column C. If yes, I wish to have the corresponding number
from
column A
put into column D.
e.g.
1 abc defghij 2
2 efgh xyzxyz
3 mnopq wwwabcwww 1
4 rstu wefghw 2
Is this possible with a function or a macro?
Regards
I have never user VBA
Regards
I wish to find any string from col B occurring in any of the longer
strings in col C, and if found require the index no. from col A [or
if
easier, the row no.] to be inserted in col D.
Does this make it clearer?
Col A B C D
Row
1 1 abc xxefghxxx 2
2 2 efgh xxyyyxx
3 3 mnopq xxxabcxxx 1
4 4 rstu xxxefghxxx 2
5 5 vwxy xxrstuxxx 4
Regards
Don
Thank you
The first routine works well. However I have noticed a small problem.
Some of my larger strings in column C contain more than one string
from
column B. How can I have these identified , perhaps in further columns
E,F,G,H etc
Col A B C D E F
Row
1 1 abc xxefghxxx 2
2 2 efgh xxyyyxx
3 3 mnopq xxxabcxxrstuxvwxyxx 1 4 5
4 4 rstu xxxefghxxx 2
5 5 vwxy xxrstuxxxmnopqxx 4 3
Regards