Thread: Find
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Geoff[_8_] Geoff[_8_] is offline
external usenet poster
 
Posts: 13
Default Find

shockley,
Thank you, but customers do have several locations. Your
example seems to record the last instance of the customer
but not all.
Still working on it.
Please see reply to Bernie Deitrick
Geoff
-----Original Message-----
This is how I would do it. I'm assuming that no

customer is listed twice in
the "archived" column:

Sub Tester()
LastRow1 = Cells(65536, 1).End(xlUp).Row
For i = 1 To LastRow1
NewCust = Cells(i, 1)
Set rngFind = Columns(5).Find(NewCust)
If Not rngFind Is Nothing Then
Cells(rngFind.Row, 6) = Cells(i, 2)
Else
LastRow5 = Cells(65536, 5).End(xlUp).Row
Cells(LastRow5 + 1, 5) = Cells(i, 1)
Cells(LastRow5 + 1, 6) = Cells(i, 2)
End If
Next i
End Sub

HTH,
Shockley



"Geoff" wrote in message
...
Hi,
I have 4 columns, A and B are new customers and
locations, E and F are archived customers and

locations.
I need to add new customer details to the archived list
at the end, prior to a final sort.
The following code works fine if the customer name did
not exist previously but fails otherwise.

Also because I sort both lists before doing the search,
is there a quicker way of continuing the search if
nothing is found, see comment in code?

I would be grateful if someone could correct the code

or
for any advice.

T.I.A

Geoff

Code:
Sub aaaa()
Dim rng As Range, rng1 As Range, rng3 As Range
Dim cust As Range, i As Integer, firstFind As String

Set rng = Range("A1")
Set cust = Range("E1")

With Sheets(1)
Set rng1 = .Range(.Range("A1"), .Range("A1:A" & .Range

_
("A65536").End(xlUp).Row))
Set rng3 = .Range(.Range("E1"), .Range("E1:E" & .Range

_
("E65536").End(xlUp).Row))

i = 0
For Each rng In rng1
Set cust = rng3.Find(what:=rng, _
After:=cust, _
SearchDirection:=xlNext)
firstFind = ""
If Not cust Is Nothing Then
Do Until rng.Offset(0, 1) = cust.Offset(0,

1)
Or cust.Address = firstFind
If firstFind = "" Then firstFind =
cust.Address
Set cust = rng3.FindNext(After:=cust)
i = i + 1
Loop
Else
.Range("E" & rng3.Rows.Count + i) = rng
.Range("F" & rng3.Rows.Count + i) =

rng.Offset
(0, 1)
i = i + 1
Set cust = Range("E1") 'Do I have to start
at the beginning if the list is sorted??
End If
Next rng
End With
End Sub



.