PC Review


Reply
Thread Tools Rate Thread

comparing 2 worsheets using a macro

 
 
louie
Guest
Posts: n/a
 
      25th Nov 2008
i need some help with macro. how do i compare names from b3:b50 of sheet1 to
complete listing of names(a1:a100) and employee id(b1:b100) of sheet2?
after finding a match it will output the employee id to a3:a50 of sheet1. if
it didn't find a match return blank.
ex. sheet 1 sheet 2
b3=alex a1=alex b1=001
output would be:
sheet 1
a3=001


 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      25th Nov 2008
Give this a try:

Sub terranian()
Dim lr As Long, lr2 As Long
Dim c As Range, serRng As Range, f As Range
lr = Sheets(1).Cells(Rows.Count, 2).End(xlUp).Row
lr2 = Sheets(2).Cells(Rows.Count, 1).End(xlUp).Row
Set serRng = Sheets(2).Range("A1:A" & lr2)
For Each c In Sheets(1).Range("B3:B" & lr)
Set f = serRng.Find(c.Value, LookIn:=xlValues, _
MatchCase:=False)
If Not f Is Nothing Then
f.Offset(0, 1).Copy Sheets(1).Range("A" & c.Row)
End If
Next
End Sub

Copy this code to your standard VBA module. You might want to substitute
the sheets names for the index numbers that I used, unless they are in the
correct order as written.


"louie" wrote:

> i need some help with macro. how do i compare names from b3:b50 of sheet1 to
> complete listing of names(a1:a100) and employee id(b1:b100) of sheet2?
> after finding a match it will output the employee id to a3:a50 of sheet1. if
> it didn't find a match return blank.
> ex. sheet 1 sheet 2
> b3=alex a1=alex b1=001
> output would be:
> sheet 1
> a3=001
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Run macro in protected worsheets Homey Microsoft Excel Programming 0 24th Apr 2009 03:54 PM
macro comparing two different lists computers hate me Microsoft Excel Programming 8 1st Aug 2008 05:37 PM
comparing text with macro =?Utf-8?B?TWljaGFlbCBB?= Microsoft Excel Programming 1 12th Mar 2005 04:05 AM
Macro for comparing two spreadsheets Sunny Microsoft Excel Programming 1 2nd Oct 2004 12:44 PM
Comparing 2 lists - macro Scotchie Microsoft Excel Programming 1 12th Mar 2004 11:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:46 PM.