Find partial

NDude

New Member
Joined
Oct 9, 2002
Messages
6
Hi everybody,

I've been looking on the board how to do this but I can't quite find it.

I am trying to write a macro that will search for a certain value (located in sheet 2, A1) in sheet 2 (column A1:A500). I want it to copy all rows with that value. But the thing is I only want the rows where the beginning of the database matched the search criteria.

E.g.

Search criteria: ABC
Database list:
1) ABC
2) ABC
3) ABCD
4) ABCD
5) ZABC
6) 12ABC

I only want nr's 1-4 and not 5 and 6 (what find usually gives).

Any ideas?

NDude
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi NDude,

Welcome to the board. :)

Try this.<pre>
Sub findtext()
Dim FindMe As String, c As Range, TestArea As Range, firstaddress As String

FindMe = "ABC" & "*"
Set TestArea = ThisWorkbook.Sheets("Sheet2").Range("A1:A500")

With TestArea
Set c = .Find(What:=FindMe, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If Not c Is Nothing Then
firstaddress = c.Address
Do
c.Interior.ColorIndex = 4
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address<> firstaddress
End If
End With

Set TestArea = Nothing
Set c = Nothing

End Sub</pre>

HTH

EDIT: JP - you're too quick! :wink:

_________________<font color="blue"> «««<font color="red">¤<font color="blue"><font size=+1>Richie</font><font color="red">¤<font color="blue"> »»»</font>

caffeine_sample.gif
</gif>
This message was edited by Richie(UK) on 2002-10-10 11:36
 
Upvote 0

Forum statistics

Threads
1,214,551
Messages
6,120,156
Members
448,948
Latest member
spamiki

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top