View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson[_4_] Greg Wilson[_4_] is offline
external usenet poster
 
Posts: 218
Default Maybe this isn't possible to match name and copy?

The following code demos my interpretation of the
mechanics of what you want.

Assumed is that the number of sheets are fixed, in this
case Sheet1 to Sheet4. And for each "name" on Sheet1 as
listed in Column A, you want to look for a match in all of
the other 3 sheets. If a match is found, then copy the
contents from the cell immediately to the right (Col. B)
of the cell in Sheet1 containing the particular "name".
Transfer this value to the cell immediately to the right
of the matching cell in the other worksheet (Just a guess
as to where you wanted it).

The term "name" is assumed to mean a person's name, city
name or such - not a named range. To test the code:
1) Ensure that the workbook has at least four worksheets.
2) In Column A of Sheet1 enter the list of names. You can
leave gaps between them.
3) Also, enter in Col. B a unique value opposite each
name.
4) In the other sheets, randomly enter text values, the
majority NOT being one of the names in Sheet1 but with one
or more matching one or more of the names.
4) Run the code.
5) Let us know to what extent this interpretation is
incorrect. Note that it worked for me instantaneously when
I tested it.

Sub XYZ()
Dim MainSheet As Worksheet, WS As Worksheet
Dim Rng1 As Range, Rng2 As Range
Dim C As Range, CC As Range
Dim i As Integer, ShtArr As Variant
Dim FirstAdd As String

On Error Resume Next
Set MainSheet = Sheets(1)
ShtArr = Array(Sheets(2), Sheets(3), Sheets(4))
Set Rng1 = MainSheet.Columns(1).SpecialCells
(xlCellTypeConstants)
For Each C In Rng1.Cells
For i = 0 To 2
Set Rng2 = ShtArr(i).UsedRange.SpecialCells
(xlCellTypeConstants)
Set CC = Rng2.Find(What:=C.Value, LookIn:=xlValues)
If Not CC Is Nothing Then
FirstAdd = CC.Address
CC.Offset(, 1) = C.Offset(, 1)
Do While Not CC.Address = FirstAdd
Set CC = Rng2.FindNext
If Not CC Is Nothing Then CC.Offset(, 1) = C.Offset(, 1)
Loop
End If
Next
Next
On Error GoTo 0
End Sub

Regards,
Greg
(VBA amateur)

-----Original Message-----
If there is a name on a sheet other than sheet 1, and it

matches a name on
sheet1, colA, copy the contents of colB of that row to

the sheet is matches?

I had asked this earlier and was given an answer, but the

answer didn't do
anything.

Thanks for your assistanct and thanks if this isn't

possible also.


.