View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default Returning to last cell in a do until loop

Sorry for the late response, I lost my internet connection..

Ok Try this one

Sub Tester()
Dim FirstAddress As String
Dim myArr As Variant
Dim rng As Range
Dim I As Long

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

With Range("B:B")

.Offset(0, 1).ClearContents
'clear the cells in the column to the right, Col C in this example

For I = LBound(myArr) To UBound(myArr)
Set rng = .Find(What:=myArr(I), _
After:=Range("B" & Rows.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
'If you want to find a part of the rng.value then use xlPart
'if you use LookIn:=xlValues it will also work with a
'formula cell that evaluates to "E"

If Not rng Is Nothing Then
FirstAddress = rng.Address
Do
rng.Offset(0, 1).Value = rng.Offset(0, -1).Value
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


"Matilda" wrote in message ...
Thanks, Ron!

A picture of my data:

Column A SearchColumn DestColumn

Mary E Mary
Joan LD
Peter N
Alex E Alex
Eddie D

I want to loop down SearchColumn until I find a certain value (eg "E"), then
take the value from the offset -1 cell and write it to DestColumn.
I then want to resume search at last valid cell in SearchColumn and repeat
the process.

"Ron de Bruin" wrote:

Hi Matilda

In which cell do you want to copy every value you find in the column
I will make a example for you if you give me this information

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


"Matilda" wrote in message ...
Dear Undisguised Angels,
I am wanting to loop through a column looking for a value, then write that
value to another cell, then return to the column to continue the search to
the end. I can get to the target cell, but how can I return to the last
"true" cell before continuing the loop?

I'm trying a for....next loop but I'm afraid the syntax is eluding me.

Any help appreciated