#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Macro Error Help

Hello, I am fairly new at VBA and created a macro to search for particular
text and then highlight the entire row when the text is found, but if one of
the text values is missing, the macro errors. I believe the Dim V is the way
to go, but I've it written wrong. Please help.

This is my formatting code that if all the values are found it works fine.
Cells.Find(What:="COMPENSATION & FRINGE", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
With Selection.EntireRow.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
Cells.Find(What:="ADVERTISING,DIRECT MAIL,COLL2", After:=ActiveCell,
LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
With Selection.EntireRow.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
--
~ Chris
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default Macro Error Help

Just change a,b,c,d to your text. Since you are looking for PART, could even
be "comp","adv", UNLESS they are part of any possible word. So, better to
use the whole text.


Sub Findemall()
On Error Resume Next
For Each mStr In Array("a", "b", "c", "d")
Cells.Find(What:=mStr, After:=ActiveCell, _
LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False).entirerow.Interior.ColorIndex = 36
Next mStr
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"C. Hernandez" wrote in message
...
Hello, I am fairly new at VBA and created a macro to search for particular
text and then highlight the entire row when the text is found, but if one
of
the text values is missing, the macro errors. I believe the Dim V is the
way
to go, but I've it written wrong. Please help.

This is my formatting code that if all the values are found it works fine.
Cells.Find(What:="COMPENSATION & FRINGE", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
With Selection.EntireRow.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
Cells.Find(What:="ADVERTISING,DIRECT MAIL,COLL2", After:=ActiveCell,
LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
With Selection.EntireRow.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
--
~ Chris


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Macro Error Help

Thank you so much! That worked like a charm.
--
~ Chris


"Don Guillett" wrote:

Just change a,b,c,d to your text. Since you are looking for PART, could even
be "comp","adv", UNLESS they are part of any possible word. So, better to
use the whole text.


Sub Findemall()
On Error Resume Next
For Each mStr In Array("a", "b", "c", "d")
Cells.Find(What:=mStr, After:=ActiveCell, _
LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False).entirerow.Interior.ColorIndex = 36
Next mStr
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"C. Hernandez" wrote in message
...
Hello, I am fairly new at VBA and created a macro to search for particular
text and then highlight the entire row when the text is found, but if one
of
the text values is missing, the macro errors. I believe the Dim V is the
way
to go, but I've it written wrong. Please help.

This is my formatting code that if all the values are found it works fine.
Cells.Find(What:="COMPENSATION & FRINGE", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
With Selection.EntireRow.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
Cells.Find(What:="ADVERTISING,DIRECT MAIL,COLL2", After:=ActiveCell,
LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
With Selection.EntireRow.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
--
~ Chris



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default Macro Error Help

Glad to help

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"C. Hernandez" wrote in message
...
Thank you so much! That worked like a charm.
--
~ Chris


"Don Guillett" wrote:

Just change a,b,c,d to your text. Since you are looking for PART, could
even
be "comp","adv", UNLESS they are part of any possible word. So, better to
use the whole text.


Sub Findemall()
On Error Resume Next
For Each mStr In Array("a", "b", "c", "d")
Cells.Find(What:=mStr, After:=ActiveCell, _
LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False).entirerow.Interior.ColorIndex = 36
Next mStr
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"C. Hernandez" wrote in message
...
Hello, I am fairly new at VBA and created a macro to search for
particular
text and then highlight the entire row when the text is found, but if
one
of
the text values is missing, the macro errors. I believe the Dim V is
the
way
to go, but I've it written wrong. Please help.

This is my formatting code that if all the values are found it works
fine.
Cells.Find(What:="COMPENSATION & FRINGE", After:=ActiveCell,
LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
With Selection.EntireRow.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
Cells.Find(What:="ADVERTISING,DIRECT MAIL,COLL2", After:=ActiveCell,
LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
With Selection.EntireRow.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
--
~ Chris




  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,805
Default Macro Error Help

Since FIND returns an error when it fails to find the search string you need
to use
ON ERROR before the FIND..

ON ERROR RESUME NEXT
or
ON ERROR GOTO 0
or
ON ERROR GOTO ErrorHandler

and have the label at the end of the macro
ErorHandler:
'Code to handle error

"C. Hernandez" wrote:

Hello, I am fairly new at VBA and created a macro to search for particular
text and then highlight the entire row when the text is found, but if one of
the text values is missing, the macro errors. I believe the Dim V is the way
to go, but I've it written wrong. Please help.

This is my formatting code that if all the values are found it works fine.
Cells.Find(What:="COMPENSATION & FRINGE", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
With Selection.EntireRow.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
Cells.Find(What:="ADVERTISING,DIRECT MAIL,COLL2", After:=ActiveCell,
LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
With Selection.EntireRow.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
--
~ Chris



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,805
Default Macro Error Help

ON ERROR GOTO 0 was just given an illustration.

"The first form, On Error Goto 0, is the default mode in VBA. This
indicates that when a run time error occurs VBA should display its standard
run time error message box, allowing you to enter the code in debug mode or
to terminate the VBA program. When On Error Goto 0 is in effect, it is the
same as having no enabled error handler. Any error will cause VBA to display
its standard error message box."

See http://www.cpearson.com/excel/ErrorHandling.htm for details.

"C. Hernandez" wrote:

Hello, I am fairly new at VBA and created a macro to search for particular
text and then highlight the entire row when the text is found, but if one of
the text values is missing, the macro errors. I believe the Dim V is the way
to go, but I've it written wrong. Please help.

This is my formatting code that if all the values are found it works fine.
Cells.Find(What:="COMPENSATION & FRINGE", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
With Selection.EntireRow.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
Cells.Find(What:="ADVERTISING,DIRECT MAIL,COLL2", After:=ActiveCell,
LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
With Selection.EntireRow.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
--
~ Chris

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Worksheet Functions 1 May 3rd 08 02:35 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Discussion (Misc queries) 1 May 3rd 08 10:52 AM
Macro error MikeD1224 Excel Discussion (Misc queries) 1 March 9th 07 12:28 AM
Macro error : Application-defined or object-defined error Joe Excel Discussion (Misc queries) 3 January 27th 06 02:32 PM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM


All times are GMT +1. The time now is 12:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"