Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find value loop not working

Hi.

This loop is driving me nuts.

I want to search in a range ("A1:U50") to find cells containing th
word "totals" (there is other text in the cell);

when I find such a cell, I want to apply certain formatting to a cel
below it (this part I am ok with).

WHen it finds all the cells, I want the loop to end, but it doesn'
stop!

My code

Sub FormatMonths ()

With worksheets("unit forecast").range("A1:U50")


chktot=cells.find(what:="*totals*").activate

Do while chcktot=true
activecell.offset(1,0).range("a1").select
Selection.font.colorindex=3

cells.find(what:="*totals*").activate

Loop

End With

End Sub


Please help if you can.
CHristiane



:confused

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Find value loop not working

Hi Christiane,

Try this

With Worksheets("unit forecast").Range("A1:U50")
On Error Resume Next
Set oCell = .Find(what:="totals", lookat:=xlPart)
If Not oCell Is Nothing Then
sFirst = oCell.Address
Do
oCell.Offset(1, 0).Font.ColorIndex = 3
Set oCell = .FindNext(oCell)
Loop While Not oCell Is Nothing And oCell.Address < sFirst
End If
End With

--

HTH

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

"Christiane " wrote in message
...
Hi.

This loop is driving me nuts.

I want to search in a range ("A1:U50") to find cells containing the
word "totals" (there is other text in the cell);

when I find such a cell, I want to apply certain formatting to a cell
below it (this part I am ok with).

WHen it finds all the cells, I want the loop to end, but it doesn't
stop!

My code

Sub FormatMonths ()

With worksheets("unit forecast").range("A1:U50")


chktot=cells.find(what:="*totals*").activate

Do while chcktot=true
activecell.offset(1,0).range("a1").select
Selection.font.colorindex=3

cells.find(what:="*totals*").activate

Loop

End With

End Sub


Please help if you can.
CHristiane






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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Find value loop not working

Hi Christiane

Try this

For changing the Font color use this .Font.ColorIndex = 0
'change the font in the column to Automatic rng.Font.ColorIndex = 3
'make the font of the cell red
Sub Color_cells_in_Range()
Dim FirstAddress As String
Dim myArr As Variant
Dim rng As Range
Dim I As Long

Application.ScreenUpdating = False
myArr = Array("totals")
'You can also use more values in the Array
'myArr = Array("ron", "dave")

With Sheets("Sheet1").Range("A1:U50")

.Interior.ColorIndex = xlColorIndexNone
'change the fill color to "no fill" in all cells

For I = LBound(myArr) To UBound(myArr)
Set rng = .Find(What:=myArr(I), _
After:=Range("A1"), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
'if you use LookIn:=xlValues it will also work with a
'a formula cell that evaluates to "ron"

If Not rng Is Nothing Then
FirstAddress = rng.Address
Do
rng.Interior.ColorIndex = 3
'make the cell red
Set rng = .FindNext(rng)
Loop While Not rng Is Nothing And rng.Address < FirstAddress
End If
Next I
End With
Application.ScreenUpdating = True
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Christiane " wrote in message ...
Hi.

This loop is driving me nuts.

I want to search in a range ("A1:U50") to find cells containing the
word "totals" (there is other text in the cell);

when I find such a cell, I want to apply certain formatting to a cell
below it (this part I am ok with).

WHen it finds all the cells, I want the loop to end, but it doesn't
stop!

My code

Sub FormatMonths ()

With worksheets("unit forecast").range("A1:U50")


chktot=cells.find(what:="*totals*").activate

Do while chcktot=true
activecell.offset(1,0).range("a1").select
Selection.font.colorindex=3

cells.find(what:="*totals*").activate

Loop

End With

End Sub


Please help if you can.
CHristiane






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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find value loop not working

Thank you.

It works fine

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

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
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
Loop all Sheets not working. Pank New Users to Excel 12 February 27th 07 11:55 AM
On Error GoTo Label in a loop only working once. Ken Johnson Charts and Charting in Excel 4 July 5th 06 09:39 PM
Find & loop in VBA Noemi Excel Discussion (Misc queries) 3 January 25th 06 03:39 AM
Loop - for each sheet not working? Shetty Excel Programming 6 January 15th 04 02:22 PM


All times are GMT +1. The time now is 01:20 PM.

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

About Us

"It's about Microsoft Excel"