Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Comparing cells

I'm looking to compare values in 2 columns in two
different work sheets... If for example; If the ID in
sheet 1 A1:A10 is equal to ID in sheet 2 D1:D10, then
copy the adjacent 3 cells to Sheet 1...

Sheet 1

A B C D E F G
12
13
14

Sheet 2

D E F G
11 1 2 3
13 4 5 6
16 7 8 9
14 3 2 1

Result after Function;

Sheet 1

A B C D E F G
12
13 4 5 6
14 3 2 1

Any help would be greatly appreciated;
Thanks
Kevin
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Comparing cells

Sub CopyIDData()
Dim rng As Range
Dim rng1 As Range
Dim cell As Range
Dim res As Variant

With Worksheets("sheet1")
Set rng = .Range(.Range("A1"), .Range("A1").End(xlDown))
End With
With Worksheets("Sheet2")
Set rng1 = .Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
End With

For Each cell In rng
res = Application.Match(cell, rng1, 0)
If Not IsError(res) Then
rng1(res, 2).Resize(1, 3).Copy Destination:=cell.Offset(0, 1)
End If
Next
End Sub


--
Regards,
Tom Ogilvy


wrote in message
...
I'm looking to compare values in 2 columns in two
different work sheets... If for example; If the ID in
sheet 1 A1:A10 is equal to ID in sheet 2 D1:D10, then
copy the adjacent 3 cells to Sheet 1...

Sheet 1

A B C D E F G
12
13
14

Sheet 2

D E F G
11 1 2 3
13 4 5 6
16 7 8 9
14 3 2 1

Result after Function;

Sheet 1

A B C D E F G
12
13 4 5 6
14 3 2 1

Any help would be greatly appreciated;
Thanks
Kevin



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
comparing cells James Excel Discussion (Misc queries) 1 November 18th 08 10:17 PM
Comparing cells when they are not exactly the same Garry Excel Discussion (Misc queries) 2 April 2nd 07 10:26 AM
comparing cells Nooby Excel Discussion (Misc queries) 3 May 19th 06 06:52 PM
comparing cells Help me Excel Worksheet Functions 1 May 9th 06 10:01 PM
Comparing two cells Mandeep Dhami Excel Discussion (Misc queries) 2 March 30th 06 07:30 AM


All times are GMT +1. The time now is 08:45 AM.

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"