Need Help With Code Quick!!

  • Thread starter Thread starter alexm999
  • Start date Start date
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...
 
Only look in column A might be a start

Cells.Find(WHAT:="EXT"

would be

Columns(1).Find(WHAT:="EXT"
 
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.
 
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.
 
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.
 
Back
Top