Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / January 2007

Tip: Looking for answers? Try searching our database.

Code glitches

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
2D Rick - 07 Jan 2007 14:33 GMT
I want to look at a range of  cells and find "AGT".
When a cell containing "AGT" is found I want to Highlite it in yellow.

The below code doesn't find all the cells.
I have bumped intCount up to 1000 and this is no help.

Help, Rick

Sub Macro3()

Dim intCount As Integer
Dim x

intCount = Application.CountIf(Range("B1:F13"), "AGT")

For x = 1 To intCount

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

   ActiveCell.Select
   With Selection.Interior
       .ColorIndex = 6
       .Pattern = xlSolid
   End With
   
   Cells.FindNext(After:=ActiveCell).Activate
Next

End Sub
Don Guillett - 07 Jan 2007 14:52 GMT
Your 1 to intcount is only counting the NUMBER of AGT's . Try looking in VBA
Help  for FINDNEXT and changing the example given instead of your effort.
Also you do NOT need to make any selections. Post back if you can't figure
it out.

Signature

Don Guillett
SalesAid Software
dguillett1@austin.rr.com

>I want to look at a range of  cells and find "AGT".
> When a cell containing "AGT" is found I want to Highlite it in yellow.
[quoted text clipped - 29 lines]
>
> End Sub
2D Rick - 07 Jan 2007 20:44 GMT
FINDNEXT
> Your 1 to intcount is only counting the NUMBER of AGT's . Try looking in VBA
> Help  for FINDNEXT and changing the example given instead of your effort.
[quoted text clipped - 38 lines]
> >
> > End Sub
2D Rick - 07 Jan 2007 20:58 GMT
FINDNEXT worked perfect, thanks Don
Rick

> Your 1 to intcount is only counting the NUMBER of AGT's . Try looking in VBA
> Help  for FINDNEXT and changing the example given instead of your effort.
[quoted text clipped - 38 lines]
> >
> > End Sub
Bob Phillips - 07 Jan 2007 15:14 GMT
Dim cell As Range
Dim sFirst As String

   With Range("B1:F13")

       Set cell = .Find(What:="AGT", _
                        After:=ActiveCell, _
                        LookIn:=xlFormulas, _
                        LookAt:=xlPart, _
                        SearchOrder:=xlByRows, _
                        SearchDirection:=xlNext, _
                        MatchCase:=False, _
                        SearchFormat:=False)

       If Not cell Is Nothing Then
           sFirst = cell.Address
           Do
               cell.Interior.ColorIndex = 6
               cell.Interior.Pattern = xlSolid
               Set cell = Cells.FindNext(cell)
           Loop While Not cell Is Nothing And sFirst <> cell.Address
       End If

   End With

Signature

---
HTH

Bob

(change the xxxx to gmail if mailing direct)

>I want to look at a range of  cells and find "AGT".
> When a cell containing "AGT" is found I want to Highlite it in yellow.
[quoted text clipped - 29 lines]
>
> End Sub
2D Rick - 07 Jan 2007 21:01 GMT
FINDNEXT worked perfect, thanks Bob
Rick

> Dim cell As Range
> Dim sFirst As String
[quoted text clipped - 62 lines]
> >
> > End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.