Need Help With Code Quick!!

A

alexm999

Here's my code:
Set ofound = Cells.Find(WHAT:="EXT", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=True)
If Not ofound Is Nothing Then
ofound.Activate
If Trim(ofound) = "EXT" Then
ActiveCell.Offset(rowOffset:=0, columnOffset:=4).Activate
Selection.Copy
Windows("BOOK1.XLS").Activate
Range("D3").Select
ActiveSheet.Paste

I want to find the word EXT in column A only, how do i narrow my search
down????? here is another EXT in Column C that it is referencing. I need
column A...
 
T

Tom Ogilvy

Only look in column A might be a start

Cells.Find(WHAT:="EXT"

would be

Columns(1).Find(WHAT:="EXT"
 
A

alexm999

Works Great thanks!

But...

What if the word EXT is not there? depending on the day, EXT may no
show up. how can i get it to search for EXT and then if not found, mov
on to the next search, but if found run the script i listed above.
 
T

Tom Ogilvy

Guess you didn't write any of this code, because it is pretty much is set up
to act the way you describe.


Dim oFound as Range
Set ofound = Columns(1).Find(WHAT:="EXT", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=True)
If Not ofound Is Nothing Then
' this is only run if EXT is found
ofound.Activate
If Trim(ofound) = "EXT" Then
ActiveCell.Offset(rowOffset:=0, columnOffset:=4).Activate
Selection.Copy
Windows("BOOK1.XLS").Activate
Range("D3").Select
ActiveSheet.Paste
Application.goto oFound
End if ' trim(ofound) = "EXT"
End if ' Not ofound is Nothing

the test, IF not ofound is nothing then
only does the above copy and paste if a cell with EXT was found in column 1.
Otherwise it drops down to the End If and if the code after that is another
search, it would do that.

I indented the code in the If Then; End if block to make that clearer.
 
C

cmdecker2

The clue is to decide if you want to do two searches or one and if that ends
up blank then another. That determins to in clude in end if statement or
not.
Carl


Tom Ogilvy said:
Guess you didn't write any of this code, because it is pretty much is set up
to act the way you describe.


Dim oFound as Range
Set ofound = Columns(1).Find(WHAT:="EXT", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=True)
If Not ofound Is Nothing Then
' this is only run if EXT is found
ofound.Activate
If Trim(ofound) = "EXT" Then
ActiveCell.Offset(rowOffset:=0, columnOffset:=4).Activate
Selection.Copy
Windows("BOOK1.XLS").Activate
Range("D3").Select
ActiveSheet.Paste
Application.goto oFound
End if ' trim(ofound) = "EXT"
End if ' Not ofound is Nothing

the test, IF not ofound is nothing then
only does the above copy and paste if a cell with EXT was found in column 1.
Otherwise it drops down to the End If and if the code after that is another
search, it would do that.

I indented the code in the If Then; End if block to make that clearer.
 

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

Top