VBA Code to FIND

C

Christine

Hello all, thanks in advance for your assistance.

I am using a macro to look up a value, find that value in another
sheet, then copy from that row to another workbook.

Clear as mud? The problem in, the value will not always be the same.
But the code puts the value, not the fact that I pasted the value,
into the FIND value. See below:

Selection.Find(What:="MI071001", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

The value "MI071001" will not always be the same. I want it to find
the value and paste it into Find each time it runs. Does this make
sense?

Christine
 
A

Alex@JPCS

Christine,

Have you tried:

Dim sSearchText as String

.... at some point in the program:
sSearchText = "MI071001" -- or pick it up from a cell, or an InputBox,
or an array or .....

..... and then:
Selection.Find(What:=sSearchText, After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

HTH,

Alex@JPCS
 
C

Christine Flott

Alex,

Thanks a bunch. However, I think I need a SET statement too, don't I?
(At least that's what I gather for the error message I get.) How does
the SET statement work?

Thanks again,

The VBA Neophyte
Christine
 
A

Alex Wolff

You should be able to use a variable instead of the actual
value assuming the value you want to find exist in cell
(1,1) of the activesheet then:


StrMyVar = ActiveSheet.Cells(1,1)

Selection.Find(What:=StrMyVar, After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate


Hope this helps if you had'nt already figured it out.

Alex-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top