ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need Help With CODE!!! (https://www.excelbanter.com/excel-programming/291781-need-help-code.html)

alexm999[_52_]

Need Help With CODE!!!
 
I run a standard find macro but if the file i try to import does not
have the particular find command (in the sample case below it's "PUP")
then my code breaks and I have an error
Is there anything i can input that will allow me to say that if the
word "PUP" is not there, then dont do anything, but if it's there, then
run my code below.



Windows("2.txt").Activate
Cells.Find(What:="PUP", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Offset(rowOffset:=0, columnOffset:=6).Activate
Selection.Copy
Windows("DAILY OPERATIONS_2004.xls").Activate
Range("K10").Select
ActiveSheet.Paste


---
Message posted from http://www.ExcelForum.com/


Ed[_9_]

Need Help With CODE!!!
 
Look through the examples in the VBA Help under On Error Statement and On
Error Statement Examples - you should find something that will fit your
code.

Ed

"alexm999 " wrote in message
...
I run a standard find macro but if the file i try to import does not
have the particular find command (in the sample case below it's "PUP")
then my code breaks and I have an error
Is there anything i can input that will allow me to say that if the
word "PUP" is not there, then dont do anything, but if it's there, then
run my code below.



Windows("2.txt").Activate
Cells.Find(What:="PUP", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Offset(rowOffset:=0, columnOffset:=6).Activate
Selection.Copy
Windows("DAILY OPERATIONS_2004.xls").Activate
Range("K10").Select
ActiveSheet.Paste


---
Message posted from http://www.ExcelForum.com/




alexm999[_53_]

Need Help With CODE!!!
 
I did check. I'm new to VB and dont know what to put in exactly.
Can anyone help

--
Message posted from http://www.ExcelForum.com


Tom Ogilvy

Need Help With CODE!!!
 
On Error Resume Next
Range.Find(Target).Activate
On Error goto 0

--
regards,
Tom Ogilvy

"alexm999 " wrote in message
...
I did check. I'm new to VB and dont know what to put in exactly.
Can anyone help?


---
Message posted from http://www.ExcelForum.com/




alexm999[_54_]

Need Help With CODE!!!
 
What do i put in for "target"

--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

Need Help With CODE!!!
 
Alex,

Try this alternative

Windows("2.txt").Activate
Set ofound = Cells.Find(What:="PUP", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not ofound Is Nothing Then
ActiveCell.Offset(rowOffset:=0, columnOffset:=6).Activate
Selection.Copy
Windows("DAILY OPERATIONS_2004.xls").Activate
Range("K10").Select
ActiveSheet.Paste

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"alexm999 " wrote in message
...
What do i put in for "target" ?


---
Message posted from http://www.ExcelForum.com/




alexm999[_55_]

Need Help With CODE!!!
 
Thanks for the code.
It still populates something into the cell, is there a way i can get i
to not populate the cell if what i'm searching for is not found

--
Message posted from http://www.ExcelForum.com


Charles

Need Help With CODE!!!
 
Alix,

I add the Exit sub in Bob's code it should exit the sub if PUP not
found.

HTH

Charles




Windows("2.txt").Activate
Set ofound = Cells.Find(What:="PUP", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not ofound Is Nothing Then Exit Sub<<<< I add this
ActiveCell.Offset(rowOffset:=0, columnOffset:=6).Activate
Selection.Copy
Windows("DAILY OPERATIONS_2004.xls").Activate
Range("K10").Select
ActiveSheet.Paste


---
Message posted from http://www.ExcelForum.com/


Tom Ogilvy

Need Help With CODE!!!
 
This guy is using recorder code. By removing the activate, you have done
nothing with the found cell. I am sure he doesn't want to exit if not
found. He just wants to process only if found, then regardless, move on to
the next search and copy. Betcha.

Windows("2.txt").Activate
Set ofound = Cells.Find(What:="PUP", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not ofound Is Nothing Then
ofound.Activate
ActiveCell.Offset(rowOffset:=0, columnOffset:=6).Activate
Selection.Copy
Windows("DAILY OPERATIONS_2004.xls").Activate
Range("K10").Select
ActiveSheet.Paste
Windows("2.txt").Activate
End if

--
Regards,
Tom Ogilvy



"Charles " wrote in message
...
Alix,

I add the Exit sub in Bob's code it should exit the sub if PUP not
found.

HTH

Charles




Windows("2.txt").Activate
Set ofound = Cells.Find(What:="PUP", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not ofound Is Nothing Then Exit Sub<<<< I add this
ActiveCell.Offset(rowOffset:=0, columnOffset:=6).Activate
Selection.Copy
Windows("DAILY OPERATIONS_2004.xls").Activate
Range("K10").Select
ActiveSheet.Paste


---
Message posted from http://www.ExcelForum.com/




alexm999[_57_]

Need Help With CODE!!!
 
Here's something to ponder

I have 2 codes; DDC and DDCE

data needs to be pulled from both onto a spreadsheet.
If DDC is not there and DDCE is there, and I do a find for DDCE, my DD
column will populate with DDCE data. Is there a way to isolate or mak
the macro not pull in false data

--
Message posted from http://www.ExcelForum.com


Tom Ogilvy

Need Help With CODE!!!
 
See answer to your later posting on this topic.

--
Regards,
Tom Ogilvy

"alexm999 " wrote in message
...
Here's something to ponder

I have 2 codes; DDC and DDCE

data needs to be pulled from both onto a spreadsheet.
If DDC is not there and DDCE is there, and I do a find for DDCE, my DDC
column will populate with DDCE data. Is there a way to isolate or make
the macro not pull in false data.


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 03:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com