Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Find - Sorry - Please see this

Hi,
Apologies, I had trouble with indenting the code, I
tabbed and the message was transmitted before I was ready.
To reiterate:
I have 4 columns, Col A and B are new customers names and
locations, Col E and F are archived details. I need to
add new customer details to the end of the archived
lists prior to a final sort. Example
Col A Col B Col E Col F
Cust1 Loc1 Cust1 Loc1
Cust2 Loc1 Cust2 Loc1
Cust2 Loc2 Cust3 Loc1
Cust2 Loc3 Cust3 Loc2
Cust3 Loc1 Cust4 Loc1
I wish to add Cust2, Loc2 and Cust2, Loc3 to the archive.

The following code works fine if the customer's name did
not exist in the archive before but fails otherwise.
Also, I sort both lists prior to searching, do I have to
start the search at the beginning again if it fails to
find anything, please comment in code?

I would be grateful for any help and sorry again for the
messed up first message.

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 176
Default Find - Sorry - Please see this

Geoff,

It's OK - see my reply to your message above.

HTH,
Bernie


"Geoff" <mail@gknowles wrote in message
...
Hi,
Apologies, I had trouble with indenting the code, I
tabbed and the message was transmitted before I was ready.
To reiterate:
I have 4 columns, Col A and B are new customers names and
locations, Col E and F are archived details. I need to
add new customer details to the end of the archived
lists prior to a final sort. Example
Col A Col B Col E Col F
Cust1 Loc1 Cust1 Loc1
Cust2 Loc1 Cust2 Loc1
Cust2 Loc2 Cust3 Loc1
Cust2 Loc3 Cust3 Loc2
Cust3 Loc1 Cust4 Loc1
I wish to add Cust2, Loc2 and Cust2, Loc3 to the archive.

The following code works fine if the customer's name did
not exist in the archive before but fails otherwise.
Also, I sort both lists prior to searching, do I have to
start the search at the beginning again if it fails to
find anything, please comment in code?

I would be grateful for any help and sorry again for the
messed up first message.

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



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 First Non blank cell than find column header and return that value Silver Rose Excel Worksheet Functions 10 April 30th 07 05:56 PM
where to put results of find operation in find and replace functio DEP Excel Worksheet Functions 5 November 15th 06 07:52 PM
Despite data existing in Excel 2002 spreadsheet Find doesn't find AnnieB Excel Discussion (Misc queries) 1 June 16th 06 02:15 AM
'find' somtimes can't find numbers. I folowd the 'help' instructi. Yaron Excel Worksheet Functions 2 November 30th 05 05:46 PM
How do I find a file/spreadsheet that Excel says is Already open but I can't find it? nwtrader8 Excel Discussion (Misc queries) 5 June 21st 05 02:16 PM


All times are GMT +1. The time now is 08:32 PM.

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

About Us

"It's about Microsoft Excel"