Home |
Search |
Today's Posts |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Maybe you can set a range equal to the found cells, and then perform the
modifications after everything is found. Sub Tester1() Dim FoundRng As Range With Worksheets(1).Range("a1:a500") Set c = .Find(2, LookIn:=xlValues) If Not c Is Nothing Then Set FoundRng = c firstAddress = c.Address Do ' c.Value = 5 Set c = .FindNext(c) Set FoundRng = Union(FoundRng, c) Loop While Not c Is Nothing And c.Address < firstAddress End If End With Dim FoundCell As Range For Each FoundCell In FoundRng.Cells FoundCell.Value = 5 ' or whatever Next ' or in one fell swoop ' FoundRng.Value = 5 End Sub Find/FindNext gives a granular level of control, but if you need to just replace 2's with 5's you can use the Replace function Range("A1:A500").Replace What:=2, Replacement:=5, LookAt:=xlWhole ', etc One thing..both Find and Replace use the last-used values for unspecified parameters, so if the macro should find using part of the cell (xlPart), or the whole cell (xlWhole), specify it in the parameter LookAt. Otherwise, if someone runs the macro after they manually used Find looking at the Whole cell (or if another macro did it), that's what the next macro will do too, unless the macro specifies the LookAt parameter. See the help file for other parameters, such as MatchCase, etc. -- Tim Zych SF, CA "AlanC" wrote in message ... I am having difficulty in understanding the .FIND example in the help files. With Worksheets(1).Range("a1:a500") Set c = .Find(2, lookin:=xlValues) If Not c Is Nothing Then firstAddress = c.Address Do c.Value = 5 Set c = .FindNext(c) Loop While Not c Is Nothing And c.Address < firstAddress End If End With This works fine but in my case I need to do some reordering of rows and then continue to FINDNEXT. There appears to be a pointer set within the FIND method which is where the .Findnext(c) starts. My changes mean that the pointer is set to a row before the found occurrence and thus the .Findnext repeats or at the end of the range the repeat finds a different address for the c.address from that stored in firstaddress so loops continuously. Is the pointer addressable, modificable or am I going about it the wrong way? -- AlanC |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Understanding formula | Excel Worksheet Functions | |||
Not understanding with/end with | Excel Programming | |||
Not understanding If Not..Then nothing | Excel Programming | |||
Understanding Templates | Excel Programming | |||
Understanding declarations | Excel Programming |